Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 图形API Facebook超时_Php_Facebook_Facebook Graph Api_Cakephp - Fatal编程技术网

Php 图形API Facebook超时

Php 图形API Facebook超时,php,facebook,facebook-graph-api,cakephp,Php,Facebook,Facebook Graph Api,Cakephp,我有Facebook页面,我需要每天提取总和数据(如,post,shar…),但我运行脚本hi got data for 2或3页Facebook max,hi因总和错误而停止 我的剧本 include '../webroot/fb/facebook.php'; //Get Facebook SDK Object $config = array( 'appId' => 'codeapl', '

我有Facebook页面,我需要每天提取总和数据(如,post,shar…),但我运行脚本hi got data for 2或3页Facebook max,hi因总和错误而停止

我的剧本

include '../webroot/fb/facebook.php';
        //Get Facebook SDK Object
        $config = array(
                'appId'  => 'codeapl',
                'secret' => 'secret',
                'cookie' => true);
        $facebook = new Facebook($config);
        $this->Pag->recursive = -1;
        $pages=$this->Pag->find('all');
        foreach ($pages as $page)
        {
            //Info page
            $this->Pag->id=$page['Pag']['id'];
            $params = array('method' => 'fql.query',
                'query' =>  "SELECT pic FROM page WHERE page_id='".$page['Pag']['idpage']."'",);
            $result = $facebook->api($params);
            $this->request->data['Pag']['image']= $result[0]['pic'];
            $this->Pag->save($this->request->data);

            //Statistique
            $page_id=$page['Pag']['id'];
            $idpage=$page['Pag']['idpage'];
            $params = array('method' => 'fql.query',
                'query' =>  "SELECT fan_count,talking_about_count,pic FROM page WHERE page_id='$idpage'",);

            $result = $facebook->api($params);
            $this->loadModel('Statistique');
            $this->Statistique->create();
            $this->request->data['Statistique']['likes']= $result[0]['fan_count'];
            $this->request->data['Statistique']['talk']= $result[0]['talking_about_count'];
            $this->request->data['Statistique']['pag_id']= $page_id;

            $params = array('method' => 'fql.query',
                'query' => "select message,share_count,comments,likes from stream where source_id='$idpage' and is_published=1 limit 1000");
            $result = $facebook->api($params);
            $message=0;
            $comment=0;
            $shar=0;
            $like=0;
            foreach ($result as $value) 
            {
                $message++;
                $shar=$shar+$value['share_count'];
                if(isset ($value['likes']['count']))
                    $like=$like+$value['likes']['count'];
                $comment=$comment+$value['comments']['count'];
            }

            $this->request->data['Statistique']['posts']=$message;
            $this->request->data['Statistique']['likepost']=$like;
            $this->request->data['Statistique']['comments']=$comment;
            $this->request->data['Statistique']['char']=$shar;
            $this->Statistique->save($this->request->data);


            //pays
            $params = array('method' => 'fql.query',
                'query' =>  "SELECT value FROM insights WHERE
                    object_id='$idpage' AND metric='page_fans_country'
                    AND end_time=end_time_date('2013-04-14T07:00:00+0000') AND period=period('lifetime')",);
            $result = $facebook->api($params);
            $this->loadModel('Payspage');
            foreach ($result[0]['value'] as $key => $value)
            {
                $pays_id=$this->requestAction("/pays/setpays/$key");
                $this->Payspage->create();
                $data['Payspage']['pay_id']=$pays_id;
                $data['Payspage']['pag_id']=$page_id;
                $data['Payspage']['nombre']=$value;
                $this->Payspage->save($data);
            }
        }
错误是

Error: Maximum execution time of 60 seconds exceeded    
File: C:\wamp\www\pub\app\webroot\fb\base_facebook.php  
Line: 971

您的查询看起来很大,而Facebook API并不总是那么快。所以

  • 在PHP.ini文件中将延迟时间从60秒更改为更多
  • 或者将查询分割成更小的部分

更大的查询并不总是更好。较小的查询将允许您尽快获得第一个结果,并允许您更早地处理它或通知用户进度(考虑AJAX)。

您可以使用此代码
设置时间限制(1000000)在php函数中