Skip to content

Instantly share code, notes, and snippets.

@alhazmy13
Last active July 24, 2016 06:30
Show Gist options
  • Save alhazmy13/e5c84e3337cf19454ec6744d5bde504b to your computer and use it in GitHub Desktop.
Save alhazmy13/e5c84e3337cf19454ec6744d5bde504b to your computer and use it in GitHub Desktop.
Run PHP script in background
  • Create a daemon configuration script under /etc/init ( NOT /etc/init.d ):-

nano /etc/init/mybot.conf

code sample:

description "MyBot Daemon"
author "alhazmy13"
start on startup
stop on shutdown
respawn

exec /usr/share/myScript.php
  • alter your script file myScript.php and add below code at the top of the file:
#!/usr/bin/env php
<?php
#bash script
#while true; do ./myScript.php; done
$seconds = 5; $micro = $seconds * 1000000;
  • at end of the file add: usleep($micro);
  • create symbolic link to /usr/share/ ln -s /var/www/html/myScript.php /usr/share
  • after finish all those steps... now you can use " stop mybot | start mybot | status mybot " in terminal.
Copy link

ghost commented Jul 19, 2016

It would b helpful to automate things like DB or files backup consistently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment