I have a php console app and an Ubuntu server. I'm executing the app with this basic command:
php app.php
I want to execute it repetitively, but cronjobs is not suitable for me. Instead, I want it to execute such that when app.php finishes working it will be executed again immediately (like an infinity loop), rather than being executed again every X minutes. So I made this bash script:
while true; do
php app.php
done
this solves my problem, but the usage of while true
seems evil. Is it possible to stop this bash script, if necessary? Or can you tell me a better way to do this?
(app.php file , fetches a long list of website URLs and their content. It's like a web spider. I connect to the server via ssh , execute bash script with nohup, and then close terminal. )
Here is an example about what you can do:
To pause you can press any key without Enter. To continue you must to press Enter. To finish you must to press Ctrl+C.
If you run the script in background using:
you can stop it using the following commands:
I think you can use your script and when you want to stop it you open a terminal and:
1. Get the pid of script:
ps -ef | grep "mycript"
2. Terminate
kill -s 15 PID
or killkill -s 9 PID
it.