質問

I have script that takes long time to execute. In a result server responds in 503 error. How can I set longer execution time?

In my PHP script I set:

set_time_limit(0);
ignore_user_abort(true);
役に立ちましたか?

解決

This question is very similar to PHP Background Processes. So read that; In addition,

First you need to change the time limit in php.ini; you cannot change it in the script itself. Or in .htaccess using php_value

Second, you may be you want to modify how you interact with user more friendly so that the page uses an update; you can explore ajax; http-refresh; multipart pages for different approaches. If you are doing long calculations perhaps you can launch them in the background and update a database, retrieve the results later.

他のヒント

Despite what time-limit you set in the script, a web request might time out earlier because the client gives up, or because any proxy server in the middle gives up, or possibly if the apache server is configured to give up.

As the other answerer mentioned; the maximum_execution_time variable might help, but it would be better if you didn't leave the visitor waiting with a long delay.

Consider using a pattern that shows feedback:

  1. User initiates action; eg POST request
  2. PHP Script returns immediately with a page containing javascript or an iframe.
  3. The javascript/inner frame calls the long-running script.
  4. Every few seconds the javascript updates the user on how the script is going, using a LONGPOLL-like mechanism.
  5. On completion or error, the javascript notifies and redirects to the next page.

Have a look at maximum_execution_time.

However to my knowledge this usually needs to be set in the php.ini , on a brief look at the manual it says this should be settable by scripts if not in safe mode.

You don't know the exact error? Without it, my guess is the memory limit, have you changed that too? Check your php.ini:

memory_limit = 128M
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top