dongmei1988 2019-06-17 06:35
浏览 524

如何在php请求中获取HTTP响应

I have a cron file that runs to post images to Instagram, once the image get posted, the code updates the MySQL table as successful. some times, if the logging to Instagram was not successful (or) IP blocked then a server response shows ("status":"fail"). how to use (if) to read the http response then update MySQL as fail?

PHP Version: 5.6.35

Server http response:

{"message": "checkpoint_required", "checkpoint_url": "https://i.instagram.com/challenge/8633340132/qz34BIU1MQ/", "lock": true, "status": "fail", "error_type": "checkpoint_challenge_required"}

Current posting code:

<?php

require_once("helper/functions.php");
require_once("cron_insta_include.php");

$result_outmsg = $database->query("SELECT * FROM insta_sent");
while($row_outmsg = $database->fetch_array($result_outmsg))
{
    if($row_outmsg["report"] == "Scheduled")
    {
        $res_ch = $database->query("SELECT * FROM insta_ch WHERE serial='" . $row_outmsg["fromch"] . "'");
        $row_ch = $database->fetch_array($res_ch);
        if(($row_ch["status"] != "Blocked") && ($row_ch != false))
        {

            if((time() - $row_ch["last_used"]) > 7200)
                {
                try
                    {
                            //Insta Sending
                            $cap = "." . "

" .  $row_outmsg["body"] . "

" . "." . "

" . $row_outmsg["hash"] . "

" . "." . "

" . $row_outmsg["tonum"] . "

" . "." . "

" . time();
                            $obj = new InstagramUpload();
                            $obj->Login($row_ch["phone"], $row_ch["ch_id"]);
                            $obj->UploadPhoto($row_outmsg["img_lnk"], $cap);

                            sleep(1);
                            $database->query("UPDATE insta_sent SET report='Sent' WHERE serial='" . $row_outmsg["serial"] . "'");
                }

                catch(Exception $e)
                {
                    $database->query("UPDATE insta_sent SET report='Failed' WHERE serial='" . $row_outmsg["serial"] . "'");
                }
                    $sql_13 = "UPDATE insta_ch SET last_used='" . time() . "' WHERE serial='" . $row_outmsg["fromch"] . "'";
                    $database->query($sql_13);
            }
        }

        else
        {
            //$database->query("UPDATE insta_sent SET report='Not Sent' WHERE serial='" . $row_outmsg["serial"] . "'");
        }
    }
}

?>

  • 写回答

5条回答 默认 最新

  • doudun2565 2019-06-17 06:50
    关注
    HTTP request successfully"; else echo "
    HTTP request not successfully!"; ?>
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?