お世話になります。
現在curlを使い以下のクローリングのコードを書いています。
ネットワークの状況により、time of 30 seconds exceededが発生しました。
PHP処理のタイムアウト対策
タイムアウトの時間変更以外によい方法ありますでしょうか?
php
1public function downloadAllFile($interval = 2) 2{ 3 foreach ($this->tests as $test) { 4 $data = $this->downloadFile($test); 5 $this->saveFile($data, $test); 6 sleep($interval); 7 } 8} 9 10public function downloadFile($test) 11{ 12 $url = $this->url . $test; 13 $ch = curl_init($url); 14 curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers); 15 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 16 curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/tmp/cookie.txt"); 17 $data = curl_exec($ch); 18 curl_close($ch); 19 return $data; 20}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/30 16:22