1

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?

Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248
  • 3
    I would recommend supervisor. More on using that with Laravel here: https://laravel.com/docs/5.2/queues#supervisor-configuration – Matt McDonald May 11 '16 at 15:38
  • Yes, it's possible to run a script with Laravel initialized. See Artisan. See my answer to another similar question: http://stackoverflow.com/questions/37061770/artisancall-outside-the-laravel-framework/37106096#37106096 Anyway, Supervisor is probably what you need here – Arcesilas May 11 '16 at 15:45

0 Answers0