2013-12-16 3 views
2

PHP에서 cURL을 사용하여 한 시간 이상 소요될 수있는 스크립트를 실행하고 있습니다. 디버깅 목적으로 화면을 보면서 요청 진행 상황을 볼 수 있기를 원합니다.이 작업은 공개 사이트가 아니며 진행 상황을 확인하는 것입니다. 나는 몇 가지 시도했지만 행운이 없다. 나는 정보의 많은, 내가 ob_flush 시도했습니다php cURL 진행 모니터?

'이제 ID (123)를로드'와 같은 뭔가가 필요하지 않지만, 당 분명히 그것은 더 이상 지원되지 : 나는 또한 사용하려고했습니다 http://php.net/ob_flush

CURLOPT_PROGRESSFUNCTION하지만 거기에는 많은 문서가 없으므로 제대로 작동하지 않습니다. 내 코드는 매우 간단합니다 :

$sql = "select item_number from products order by id desc"; 
$result_sql = $db->query($sql); 
while($row = $result_sql->fetch_assoc()) 
{ 
//I'd like it to display this as it loads 
print '<br>Getting data for item_number: '.$row['item_number'] 

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL,"http://targetsite.com//".$row['item_number']); 
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl, CURLOPT_SSLVERSION, 3); 
//curl_setopt($curl, CURLOPT_HEADER, 1); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); 
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)"); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($curl, CURLOPT_VERBOSE, 1); 
} 

어떤 조언이 있습니까? 나는 정말 까다 롭지 않아, 뭔가 일이 일어나고 있다는 것을 빨리 알 수있는 가장 쉬운 방법 일뿐입니다.

+0

를 사용하는 PHP 버전? – brandonscript

+0

from php info() : PHP 버전 5.3.24 – user2029890

답변

1

당신이 PHP를 사용하는 가정> = 5.3 (이전 버전 CURLOPT_PROGRESSFUNCTION을 지원하지 않습니다) 당신과 같이 사용 :

function callback($download_size, $downloaded, $upload_size, $uploaded) 
{ 
    // do your progress stuff here 
} 

$ch = curl_init('http://www.example.com'); 

// This is required to curl give us some progress 
// if this is not set to false the progress function never 
// gets called 
curl_setopt($ch, CURLOPT_NOPROGRESS, false); 

// Set up the callback 
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'callback'); 

// Big buffer less progress info/callbacks 
// Small buffer more progress info/callbacks 
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128); 

$data = curl_exec($ch); 

출처 : 당신이 http://pastebin.com/bwb5VKpe

+0

나는 5.3을 실행 중이다. 나는 그것을 시도했다. 그것은 작동하지 않는 것 같습니다. 함수의 변수는 0을 반환합니다. 또한 'while'루프 전에 함수를 배치하면 함수를 인식하지 못하는 오류가 발생합니다. 루프 내에 배치하면 이미 호출 한 첫 번째 반복 이후에 오류가 발생합니다. – user2029890