Long computation in php results in 503 error

霸气de小男生 提交于 2019-12-10 11:30:01

问题


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);

回答1:


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.




回答2:


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.



回答3:


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.




回答4:


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


来源:https://stackoverflow.com/questions/8202002/long-computation-in-php-results-in-503-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!