2012-05-21 7 views
-1

자매 사이트를 긁어 모으는 사이트가 있지만보고하는 이유 때문에 작업을 실행하는 데 걸린 시간을 계산할 수 있기를 바랍니다. 어떻게 PHP로 접근 할 수 있습니까? 가능합니까?긁어 모으기 프로세스 타이밍

이상적인 세계에서 작업이 실제로 5 초 후에 실행될 수없는 경우이 기능을 실행 중지하고 오류를보고하고자합니다.

감사합니다. 당신이된다고 위해 컬을 사용하는 경우

답변

2

, 당신은 내가 PHP 파일에서 직접이를 실행할 수이

// create a new cURL resource 
$ch = curl_init(); 

// set URL and other appropriate options including timeout 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // capture the result in a string 
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // The number of seconds to wait while trying to connect. 
// grab the info 
if (!$result = curl_exec($ch)) 
{ 
    trigger_error(curl_error($ch)); 
} 

// close cURL resource, and free up system resources 
curl_close($ch); 

// process the $result 
+0

같은 시간 제한 기능을 사용할 수 있습니까? – David

+0

물론, php_curl 확장 기능을 활성화하고 $ url = "http://site_i_want_to_grab.com/some_page/some_id"를 설정하면됩니다 –

+0

어떻게하면 조건을 추가 할 수 있습니까? 예를 들어, 제 경우에는 다음과 같이하고 싶습니다 : if (you-can-find-the-url) {이렇게하십시오} else {그렇게하고 오류를 기록하십시오} – David