Friday 15 June 2012

curl - Unable to Download Remote File from server after using sleep in php -


Hi There is a strange problem with me downloading a remote file I downloaded some reports to send flary data I am using API. The thing is that when we first call the whispered API, we give the XML / JSON response, which contains the path to the report for download. It takes 2 minutes for the report to be ready. I'm having trouble with that thing. I wrote a script that downloads a remote file if I just paste the report link directly to work that's already ready to download. It works like a charm But I have to automate the downloading process. So I call the API first and get the download download link, so I use PHP's sleep () function to prevent execution of 3 code Tried together). Then I call the same function that I use to download the report, this time does not work successfully. Here is the file download method:

  function get_file_and_save ($ file, $ Local_path, $ newfilename) {$ err_msg = ''; $ Out = FOPN ($ local_path $ Newfilename. ".gz", 'wb'); If ($ out == FALSE) {print "file is not available & lt; br & gt;"; Go out; } $ Ch = curl_init (); $ Header = array ('content-type: app / x-gzip', 'connection: off'); Curl_setopt ($ CH, CURLOPT_FILE, $ out); Curl_setopt ($ CH, CURLOPT_HTTPHEADER, $ headers); Curl_setopt ($ ch, CURLOPT_URL, $ file); Curl_setopt ($ CH, CURLOPT_CONNECTTIMEOUT, 0); Curl_exec ($ ch); Echo "& lt; br> Curl_error ($ ch); Curl_close ($ ch); }   

I also tried to give CURLOPT_TIMEOUT but it was not working either.

download_path is working properly, it only receives the report link:

  $ query_url = 'http: // api. Flurry.com/rawData/Events?apiAccessCode= '$ ACCESS_CODE' & Amp; ApiKey = '$ API_KEY' & Amp; Starttime = '$ start_time' & Amp; EndTime = '$ End_time; $ Response = download_path ($ query_url); If ($ response) {$ response_obj = json_decode ($ response, true); If (isset ($ response_obj ['report'] ['@ reportUri'])) {$ report_link = $ response_obj ['report'] ['@ reportUri']; } If (isset ($ response_obj ['report'] ['@ reportId'])) {$ report_id = $ response_obj ['report'] ['@ reportId']; } If (isset ($ report_link) & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; nbsp; ($ report_link)) {echo '& lt; br & gt; report link: "$ report_link "& Lt; br & gt;"; Sleep (240); $ Config = array ('http' = & gt; array ('header' = & gt; accept: application / jason ',' method '=> gt;')); $ Stream = stream_context_create ($ config); $ Json = file_get_contents ($ report_link, incorrect, $ stream); Echo "& lt; east & gt;"; Print_r ($ http_response_header); Echo "& lt; / pre & gt;"; If ($ http_response_header [3] == "content-type: application / octet-stream") {get_file_and_save ($ report_link, "data-files / jez /", $ current_time); }} Else {echo "there was some error in downloading report"; }} And {$ error = true; The echo "there was some error in the generating report"; }   

There is a problem with sleeping (or ) or that I am the second night, I am unable to get it.

Check that your PHP script is running out of time and whether it is killed or not. Both webservers and PHP have maximum execution limits to prevent runaway scripts, and if your sleep is more than that limit, then it will never continue.


- request_terminate_timeout




No comments:

Post a Comment