0

I am running a CLI windows php script which is mostly a LOOP with some CMD exec functions. Problem is that these exec functions sometimes hangs up.

Can this script kill itself and restart itself ? '(for instance every 5 minutes)

yarek
  • 8,962
  • 25
  • 93
  • 180
  • When a system hangs it can't do anything so as i think you need to write an extra script which scans the running process of this file and when it finds like this process has been idle for 5 mins restart it – M A SIDDIQUI Feb 07 '17 at 10:59
  • Use a task scheduler like cron or a process manager like supervisord. – jeroen Feb 07 '17 at 11:01
  • Using cronjobs would be a solution: http://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron – Variable Feb 07 '17 at 11:02

1 Answers1

0

Can this script kill itself and restart itself?

Not really, yet you can run another instance of itself and then quit the current one.

these exec functions sometimes hangs up

Then script cannot break from this by itself other by timeouting (see set_time_limit). Or you need to have separate watchdog to monitor your script and restarting it when needed.

(for instance every 5 minutes)

Rework your code to not loop and use cron or other scheduler (see What is the Windows version of cron?) to invoke your code periodically.

Community
  • 1
  • 1
Marcin Orlowski
  • 67,279
  • 10
  • 112
  • 132
  • "Not really, yet you can run another instance of itself and then quit the current one.": how ? with an external software or inside the script itself ? – yarek Feb 07 '17 at 12:37