I have a PHP script which opens a TCP/IP connection and in theory should run indefinitely. But every once in a while, this script will crash so I would like to make sure I have one instance of this script running at all times - and if not, launch a new instance of it.
My script is written within an Laravel application, which means it needs several classes defined within my Laravel application to function. This prevents me from running a simple php myscript.php
because there's no way to bootstrap the Laravel application and make available the classes I need if I start the script from the command line.
This leaves me the options of either creating a custom Artisan command and running my script logic through that or using CURL to start my script (this allows Laravel to bootstrap since it's a HTTP call). The end goal is still to constantly have one instance of the script running at all times.
If I could run the script through the command line, I could do a ps aux | grep myscriptname.php
to see if I already have a instance of the script running - and launch an instance if I don't. But if I start the script with a CURL request, the script is logged as an apache / httpd process. The same problem occurs with running it through a custom Artisan command; I am not able to see the underlying function name of the persistent method being executed.
Is there another method here which will allow me to achieve what I am looking to do?