-1

I have a simple question that I couldn't find an answer for on the web or on StackOverflow.

I have two PHP scripts that I would like to run as daemon (not every x seconds/days).

Now I want to run them manually. I would also like them to run every time the server reboots.

What is the best practice for doing this?

If in your answer you are suggesting to use /etc/init.d/ please explain how this is done.

Ladadadada
  • 26,337
  • 7
  • 59
  • 90
Liad Livnat
  • 221
  • 1
  • 3
  • 7
  • I can't quite make sense of your request to run your scripts as a daemon and also to run them manually the way it's written. Do you want to have a daemon running but also be able to run a second copy of the script manually and have that one finish? – Ladadadada Sep 09 '13 at 12:13
  • No i want to run it from deamon now, but if the machine will restart it should run automatically – Liad Livnat Sep 09 '13 at 19:16

2 Answers2

3

you can do this with cronjob.

@reboot  php -f /var/scripts/script.php

http://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/

MiM
  • 106
  • 1
  • 9
1

Aside from the cronjob answer, which I would suggest, you can also do this inside of /etc/rc.local. If the script stays running, or runs for a period of time, you may want to fork it with & :

/usr/bin/php -f /path/to/script.php &
exit 0

Is how the line would appear in your /etc/rc.local file

Note: added the exit 0 to show you want the line above the exit call).

Jim
  • 391
  • 2
  • 8