php超时与file_get_html

时间:2014-12-02 07:13:15

标签: php simple-html-dom

我一直试图通过使用simple_html_dom lib for php从wikia网站获取一些数据。基本上我做的是使用wikia api转换为html渲染并从那里提取数据。提取后,我将这些数据泵入mysql数据库进行保存。我的问题是,通常我将拉出300条记录,并且我将卡在93条记录上,其中file_get_html为null,这将导致我的find()函数失败。我不知道为什么它停在93条记录但我尝试了各种解决方案,如

   ini_set( 'default_socket_timeout', 120 );
   set_time_limit( 120 );

基本上我将不得不访问wikia页面300次以获得这300条记录。但大多数情况下,我会在file_get_html变为null之前获得93条记录。知道如何解决这个问题?

我也有测试卷曲并且有同样的问题。

function test($url){
 $ch=curl_init();
 $timeout=5;

 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

 $result=curl_exec($ch);
 curl_close($ch);
 return $result;
 }

 $baseurl = 'http://xxxx.wikia.com/index.php?';

 foreach($resultset_wiki as $name){
  // Create DOM from URL or file
 $options = array("action"=>"render","title"=>$name['name']);
 $baseurl .= http_build_query($options,'','&');
 $html = file_get_html($baseurl);
 if($html === FALSE) {
 echo "issue here";
 }
  // this code for cURL but commented for testing with file_get_html instead
  $a = test($baseurl);
  $html = new simple_html_dom();
  $html->load($a);

    // find div stuff here and mysql data pumping here.
 }

$ resultsetwiki是一个数组,其中包含从wikia获取的标题列表,基本上resultsetwiki数据集也是在从执行搜索之前从db加载的。

实际上我会这种类型的错误

  Call to a member function find() on a non-object in 

1 个答案:

答案 0 :(得分:0)

回答了我自己的问题,似乎是我正在使用的网址,我已经更改为curl with post以发布操作和标题参数

相关问题