2008-11-06 5 views
1

계속하기 전에 PHP가 컬을 끝내기를 기다리는 방법은 무엇입니까?

$file = fopen($filepath, "w"); 
$CR = curl_init(); 
curl_setopt($CR, CURLOPT_URL, $source_path); 
curl_setopt($CR, CURLOPT_POST, 1); 
curl_setopt($CR, CURLOPT_FAILONERROR, true); 
curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($CR, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($CR, CURLOPT_FILE, $file); 
$result = curl_exec($CR); 
$error = curl_error($CR); 
print filesize($filepath); 

print filesize($filepath); 

두 번째로 실행하는 경우와 다른 결과를 얻습니다. 내 생각 엔 파일 크기가 커질 때 컬이 여전히 다운로드 중이다.

답변

2

filesize()와 같은 함수는 결과를 캐시하므로 'print filesize (...);'위의 clearstatcache()에 대한 호출을 추가하십시오.

$file = '/tmp/test12345'; 
file_put_contents($file, 'hello'); 
echo filesize($file), "\n"; 
file_put_contents($file, 'hello world, this is a test'); 
echo filesize($file), "\n"; 
clearstatcache(); 
echo filesize($file), "\n"; 

참조가

0

글쎄, 내가 같은 문제가 www.php.net/clearstatcache 예를 들면 다음과 같습니다. 컬 (curl)은 동기식 (synchronous)으로되어 있지만, 사용 방법에 따라 동기식이 아닙니다.
컬링, 프린트 또는 에코를 호출하면 내용이 무효화됩니다. 이상한 연기가 있습니다.

print_r(curls_getinfo($CR)); 

문제를 해결할 수 있습니다 한 번에 모든 일을 - 하지만이 방법을 시도 할 것이다.

관련 문제