PHP Curl download PDF files -
PHP Curl download PDF files -
what proper way download 50+ pdf files using php curl?
below code using:
$fp = fopen("test.pdf", 'w'); $ch = curl_init(); curl_setopt($ch,curlopt_proxy,"http://test:123"); curl_setopt($ch,curlopt_proxyport,123); curl_setopt ($ch, curlopt_connecttimeout, 0); curl_setopt ($ch, curlopt_timeout, 500); curl_setopt($ch,curlopt_url,"http://download/test.pdf"); curl_setopt($ch, curlopt_file, $fp); curl_exec($ch); curl_close($ch); fclose($fp);
the problem sometimes, 2-3 pdf files not downloaded (0-1 bytes in size). thought why unstable? must include else in code above?
thanks in advance
web requests in general can pretty dodgy browser , connection. there few things going wrong here remote site refusing connection, simultaneous execution of php file multiple locations. have at:
http://www.php.net/manual/en/function.curl-error.php
to seek print out error messages somewhere analysis on curl_exec.
if it's connection issue, may need introduce retry mechanism, not sure if script executed in parallel multiple locations, if is, should have @ http://php.net/manual/en/function.uniqid.php means generate reasonably unique filename first, effort download, move file intended destination file if no error returned, otherwise, retry x times.
with respect stability of curl, utilize , hasn't proven unstable me, i'm not pulling downwards binary data. i'm hoping error detection , output error messages may shed more lite on root cause here.
php
Comments
Post a Comment