Skip to content

Instantly share code, notes, and snippets.

@alhazmy13 alhazmy13/temp.md
Last active Jul 24, 2016

Embed
What would you like to do?
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.
@abdullascript

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.