1

I have a function for a wordpress plugin I'm developing that takes a lot of time. It connects to the TMDb (movies database) and retrieves one by one all movies by id (from 0 to 8000) and creates a XML document that is saved on the local server. Of course it takes a bunch of time, and PHP says "504 Gateway Time-out The server didn't respond in time."

What can I do???? any sugestions!!!

3 Answers 3

1

Assuming a one-time execution and it's bombing on you, you can set_time_limit to 0 and allow it to execute.

<?php
  set_time_limit(0); // impose no limit
?>

However, I would make sure this is not in production and it will only be ran when you want it to (otherwise this will place (and continue to place) a large load on the server).

Sign up to request clarification or add additional context in comments.

6 Comments

most servers are running in safe mode, so I can not set the time limit! I'm looking for some smart way to code it, I'm almost new in PHP, thats why I'm looking for advise.. This plugin's script will run just one time for synchronism with the db!
@Max: The other option is to output content while it's loading so it's not a "Dead connection". You can, every so many reads, perform a echo 'Working...'; flush(); which will continue to push data to the listening client until it's complete.
Thanks!! when 'flushing' I'm cleaning caches or something? Will I loose my unsaved xml document? will it extend the time I can execute the process?
@max: flush tells php to force-output of anything waiting to be sent to the client. Normally PHP holds on to the entire document's content (waiting for the entire page to be rendered) before it sends it off so it can fill the Content-Length header accurately. But, you can circumvent it by calling flush and force whatever is in the back-log to get sent to the client.
I was thinkint of something in the line of @Brad suggestion: Do it via AJAX on the client side, but download the data in chunks and inform the user when each chunk is downloaded and saved to a DB table or temp file (1 of x completed ....). Once done, compose XML, perhaps save it as a cache for later use, and show link to download it if appropiate.
|
0

Try to set:

set_time_limit(0);

at the script head. But i think it's the servers problem, you read too long. Try read in thread mode.

2 Comments

most servers are running in safe mode, so I can not set the time limit! I'm looking for some smart way to code it, I'm almost new in PHP, thats why I'm looking for advise..
i think its not possible. Need more time. Search for server which can give you it
0

I think this is not related to script timeout.

504- Gateway Timeout problem is entirely due to slow IP communication between back-end computers, possibly including the Web server.

Fix: Either use proxies or increase your cache size(search for "cache" in your php.ini and play with it) limit.

Dot

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.