简体   繁体   English

在PHP / Apache / Ubuntu上运行长时间的进程

[英]Running long process on Php/Apache/Ubuntu

I'm trying to run long process on Php/Apache/Ubuntu (AWS) 我正在尝试在Php / Apache / Ubuntu(AWS)上运行较长的过程

This is a simple process that builds a cache during the night. 这是一个简单的过程,可在夜间建立缓存。

The process can run for a few hours, and is initiate by crontab accessing a special url with curl . 该过程可以运行几个小时,可以通过crontab通过curl访问特殊的URL来启动。

Sometimes the process stops at a random with no error, I suspect that it is killed by the apache , although I set 有时,该过程随机终止且没有错误,我怀疑它是被apache杀死的,尽管我设置了

    @set_time_limit(0);
    @ini_set('max_execution_time', -1);

Is it a known issue with Php/Apache/Ubuntu? 这是Php / Apache / Ubuntu的已知问题吗?

Is there a way to solve it? 有办法解决吗?

Currently, my solution is to run the process every 5 minutes, and store the state on the disk, and continue from where it stopped. 当前,我的解决方案是每5分钟运行一次该过程,并将状态存储在磁盘上,然后从停止的位置继续。

But I would like to know more about this issue and if there is a better way to tackle it? 但是我想了解更多有关此问题的信息,是否有更好的解决方法?

NOTE: The process stops randomly or doesn't stop at all - the longer the process (ie bigger cache) the chance it will stop is higher 注意:进程随机停止或根本不停止-进程越长(即更大的缓存),停止的机会就越高

One possible reason is that the client disconnects (eg after a timeout): PHP stops the request processing by default in this case. 一个可能的原因是客户端断开连接(例如,在超时之后):默认情况下,PHP在这种情况下会停止请求处理。 To prevent this, you can use ignore_user_abort : 为了防止这种情况,您可以使用ignore_user_abort

ignore_user_abort(true);

Also note that the set_time_limit call may actually fail (eg on a restricted environment) — so it might make sense to remove the error suppression ( @ ) or explicitly check whether set_time_limit(0) returned true . 还要注意, set_time_limit调用实际上可能会失败(例如,在受限环境中),因此删除错误抑制( @ )或显式检查set_time_limit(0)是否返回true可能是有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM