在foreach循环和realod函数之后,函数不会退出

时间:2018-03-26 07:22:46

标签: php mysql codeigniter curl php-curl

我在php中有一个函数,该函数连接到多个API并从这个多API获取数据并插入到数据库中。但是当函数从上一个API获取数据时,函数不会退出。函数重新加载并再次从多个API获取数据。为什么函数重新加载?

注意:此功能在localhost中运行没有问题,但重新加载专用服务器功能

function sepehr_get_flight(){

    $query = $this->db->query('SELECT * FROM `mytable` WHERE `status` = ?', array(1));

    foreach ($query->result_array() as $domain){

        $url = $domain['url'];

        $data = array(
            "UserName"=> "",
            "Password"=> "",
        );

        $content = json_encode($data);

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

        $jsonResponse = curl_exec($curl);

        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        curl_close($curl);

        $info = json_decode($jsonResponse, true);

        $count = count($info['Priced']);

        for($i = 0; $i < $count; $i++){
           if(!empty($info)){

               // insert data to database

           }
        }

    }

    echo 'Success';
    exit();
}

0 个答案:

没有答案