Curl e 504 Gateway Time-out

hello, I download a 70MB file from the web site and I’m using this code:

function get_file($file, $local_path, $newfilename){

    $err_msg = '';
    $out = fopen($newfilename, 'wb');
    if ($out == FALSE){
      print "File non aperto!!!<br>";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_FILE, $out);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_URL, $file);
	curl_setopt($ch, CURLOPT_TIMEOUT, 12000);
	curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 12000); 
    echo "<br>Errore: ".curl_error ( $ch);


I have no problems on the local instead remote gives me the error:

504 Gateway Time-out

How can I avoid going in time-out???

thanks for the help!!!

there is no way to continue the download with curl???

You could stream it instead. Iv had major problems with this in the past and have had a certain amount of success solving it.
What you trying to do with this 70meg file and what file type is it? A csv or something?

I do read a xml file and move all the data in mysql

do you mean by streaming??
Can you give an example?? please.

If you are in control of the server that is generating the 504 response, then you probably can. Otherwise, you can contact those who are in charge of that network and ask them to improve their level of service.

Yes there is, but it will not help with the above. The download never started in the first place.

download starts … but stops with error 504

As crmalibu stated, the problem lies in how your server accesses the remote resource.

504 Gateway Timeout

The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access in attempting to complete the request.

Read this:

Its about pull parsing a file. I managed to overcome the problem you are having by using XMLReader, streaming it rather than processing the file as a whole.

Something like this:

$reader = new XMLReader();
$request = $HTTP_RAW_POST_DATA;
while ($reader->read()) {
// processing code goes here…

Thats straight out of the above link. I just processed each section of the xml file in the while loop using for loops:

if($reader->name == ‘name’){ $name=“fred”; }

Since this is streaming through each line rather the file as a whole you need to check what the current line is each time. That sort of thing.

I actually meant if statements not for loops but never mind.