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.

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

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号