1

I'm trying to run long process on 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.

Sometimes the process stops at a random with no error, I suspect that it is killed by the apache, although I set

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

Is it a known issue with 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.

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 (i.e. bigger cache) the chance it will stop is higher

6
  • Does it always stop at (approximately) the same time? Commented Sep 6, 2018 at 9:32
  • The process stops randomly or doesn't stop at all - the longer the process (i.e. bigger cache) the chance it will stop is higher Commented Sep 6, 2018 at 22:47
  • Is there enough RAM? Commented Sep 6, 2018 at 22:48
  • Yes, the process is very simple, it fetches HTML pages and store them on disk Commented Sep 6, 2018 at 22:56
  • 1
    Do you need apache in the equation? Can you just put a php interpreter on the #! line and run that directly from cron? (I bet you can.) Commented Sep 6, 2018 at 23:16

1 Answer 1

1

One possible reason is that the client disconnects (e.g. after a timeout): PHP stops the request processing by default in this case. To prevent this, you can use ignore_user_abort:

ignore_user_abort(true);

Also note that the set_time_limit call may actually fail (e.g. on a restricted environment) — so it might make sense to remove the error suppression (@) or explicitly check whether set_time_limit(0) returned true.

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

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.