dsoihsnz85757 2015-02-17 00:40
浏览 54
已采纳

PHP cURL或Multi Curl还是其他什么?

I have a PHP script which loops through a database table of URLs and call a PHP cURL for each URL, scrape the data and then save the data into a different database. Code:

$results = $wpdb->get_results("SELECT * FROM urls ORDER BY id DESC");
foreach($results as $row) {
    //PHP CURL STUFF HERE
}

The above script is run using cPanel's CRON every 12 minutes. My problem is a) the URLs needs to be scraped more often to get better results, because sometime the loop takes time to complete and some URls are not covered in the 12 minutes time.

Now.. Is the above strategy the only strategy or there is any better solution such as Multi Curl? I was thinking if I can have something like script.php?url=1 and then there is a dedicated CRON or something similar for this URL so I can track and check whats going on with this exact URL. Is this possible? If yes, how ? If there are 300 URLs in the database, I can't create 300 CRONs for it :(

Looking forward to your opinions :)=

  • 写回答

1条回答 默认 最新

  • douhao123457 2015-02-17 00:47
    关注

    Calling PHP multiple time is not a good solution. Why can't you do 300 request in 12 min? (thats really slow)

    You need to add a timeout for example

    curl_setopt($ch, CURLOPT_TIMEOUT, 10); //Each url will take 10 sec max
    

    and then display a log with the URL in it to find slow requests Use curl_errno() to detect errors

    Code 28 is timeout.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)