I have a website that provides some sort of service via REST API. All functionality has regular HTTP request-response logic. But additionally I need another PHP script that does some continuous stuff. On the one hand, this script should have an access to all core service functionality (core engine, stored procedures, etc). On the other hand, this script should keep persistent connection to third-party service and read some information from it from time to time. Additionally this script should be fault-tolerant, and it should be guaranteed that only one instance of this script is running at any time. Also there are some reasons why I can't put this task on the Cron service instead of infinite script running.
The best idea that I have at this moment is to write regular PHP script that starts with set_time_limit(0) and contains infinite loop with my stuff action and sleep after it. This script will be launched manually. Additionally I can protect this script with some sort of password to make sure that no one else could run it. What do you guys think about this solution? Won't such solution affect some unwanted FastCGI side-effect? How can I make this solution fault-tolerant? And how can I stop this script, or check if it is running? And the last thing: how can I run this script via HTTP request so that it won't block anything (kinda background-running CURL or something). Thanks!