Keep running your PHP script with foreverjs
foreverjs is very nice tool for keeping running and managing your services. Usage syntax is like that:
forever [-forever options] start [-c] [executable file] [-parameters to executable]
As you can see start and -c parameters should be in last. All things which after these will be processed by your executable file. For running a nodejs file you don’t need to -c parameter. Only start this file and pass the parameters to it. Forever options should be between forever and start expressions.
You don’t need add ampersand character (&) at last because your executable file will work in background because of foreverjs. And you don’t need redirect log output to any file because foreverjs will catch it and put logs to ~/.forever/ folder.
Examples:
Running a Nodejs app:
forever -a start app.js --param1 --param2
These param1 and param2 values passed to app.js file.
Running forever a PHP script:
forever -a -s --uid "ws-server" start -c php artisan websockets:serve --host=127.0.0.1 --port=16000
Now let’s look to foreverjs parameters:
- -a: Append to log, will stop it complaining about the log already existing.
- -s: Sileng mode, not save log output to file.
- -c: This parameter should be come after the start command. Normally foreverjs is designed for running Nodejs applications but if you want to execute different program then you must use -c parameter with start command. And this parameter should be last parameter in foreverjs. All next parameters will be passed to your executable (php).
0 yorum