Back
Sjoerd Huininga
Sjoerd Huininga
@sjoerdhuininga
23
Joined February 2018
what would be best practice running an endlless php script as a systemd service so that it won't get stuck?
what would be best practice running an endlless php script as a systemd service so that it won't get stuck?
As you said, php really isn't build for this kind of tasks. That being said, I do actually have something similar running at the day job. Fixed it by creating a lockfile in the php script; if the script fails the file gets 'unlocked' automatically. The first line in the script just checks if the lockfile is locked, if it is the script then quits; otherwise it'll start processing. Using cron I scheduled the script to start every minute; which will actually only run if the lockfile isn't locked. No high-tech solution in any sense, but it's been running for years without issue now.
Great, thanks guys! Are any of you using CI systems? How do they integrate with your source control env?
To add to that: you can just use the flock(); function. It will unlock if the script crashes