{"id":18592352,"url":"https://github.com/tankibaj/php-daemon","last_synced_at":"2026-04-16T10:35:28.964Z","repository":{"id":116077240,"uuid":"205450993","full_name":"tankibaj/php-daemon","owner":"tankibaj","description":"Permanently run a PHP script as a daemon/service","archived":false,"fork":false,"pushed_at":"2019-08-30T21:05:57.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-16T10:09:54.570Z","etag":null,"topics":["bash","linux","php","shell"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tankibaj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-30T20:15:34.000Z","updated_at":"2022-07-22T19:56:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"273abc82-4d8b-40dd-94d5-0f83037591ee","html_url":"https://github.com/tankibaj/php-daemon","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tankibaj/php-daemon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tankibaj%2Fphp-daemon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tankibaj%2Fphp-daemon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tankibaj%2Fphp-daemon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tankibaj%2Fphp-daemon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tankibaj","download_url":"https://codeload.github.com/tankibaj/php-daemon/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tankibaj%2Fphp-daemon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31882649,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T09:23:21.276Z","status":"ssl_error","status_checked_at":"2026-04-16T09:23:15.028Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","linux","php","shell"],"created_at":"2024-11-07T01:08:15.715Z","updated_at":"2026-04-16T10:35:28.917Z","avatar_url":"https://github.com/tankibaj.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"## PHP script as a Daemon/Service\n\nAssume we need to permanently run a PHP CLI script, it need to run as a daemon/service. It will support service \u003ccode\u003estart\u003c/code\u003e \u003ccode\u003estop\u003c/code\u003e commands. Okay lets start.\n\nCreate a daemon/service called:\n\n```shell\nsudo touch /etc/init.d/myPHPservice\n```\n\nOpen created daemon/service:\n\n```shell\nsudo nano /etc/init.d/myPHPservice\n```\n\nAnd paste following code\n\n```sh\n#! /bin/sh\n\n# Installation\n# - Paste these to /etc/init.d/myPHPservice\n# - chmod +x this\n#\n# Starting and stopping\n# - Start: service myPHPservice start OR /etc/init.d/myPHPservice start\n# - Stop: service myPHPservice stop OR /etc/init.d/myPHPservice stop\n\n\n\nNAME=myPHPservice\nDESC=\"Daemon for PHP CLI script\"\nPIDFILE=\"/var/run/${NAME}.pid\"\nLOGFILE=\"/var/log/${NAME}.log\"\n\nDAEMON=\"/usr/bin/php\"\nDAEMON_OPTS=\"/path/to/your/php/script.php\"\n\nSTART_OPTS=\"--start --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} ${DAEMON_OPTS}\"\nSTOP_OPTS=\"--stop --pidfile ${PIDFILE}\"\n\ntest -x $DAEMON || exit 0\n\nset -e\n\ncase \"$1\" in\n    start)\n        echo -n \"Starting ${DESC}: \"\n        start-stop-daemon $START_OPTS \u003e\u003e $LOGFILE\n        echo \"$NAME.\"\n        ;;\n    stop)\n        echo -n \"Stopping $DESC: \"\n        start-stop-daemon $STOP_OPTS\n        echo \"$NAME.\"\n        rm -f $PIDFILE\n        ;;\n    restart|force-reload)\n        echo -n \"Restarting $DESC: \"\n        start-stop-daemon $STOP_OPTS\n        sleep 1\n        start-stop-daemon $START_OPTS \u003e\u003e $LOGFILE\n        echo \"$NAME.\"\n        ;;\n    *)\n        N=/etc/init.d/$NAME\n        echo \"Usage: $N {start|stop|restart|force-reload}\" \u003e\u00262\n        exit 1\n        ;;\nesac\n\nexit 0\n```\n\nNext, make it executable by running\n\n```shell\nchmod +x /etc/init.d/myPHPservice\n```\n\nChange \u003ccode\u003eNAME\u003c/code\u003e, \u003ccode\u003eDESCRIPTION\u003c/code\u003e, \u003ccode\u003eDAEMON\u003c/code\u003e, and \u003ccode\u003eDAEMON_OPTS\u003c/code\u003e to reflect your setup.\n\nOnce done you can start the service by running \u003ccode\u003e/etc/init.d/myPHPservice\u003c/code\u003e start and stop it by running \u003ccode\u003e/etc/init.d/myservice stop\u003c/code\u003e. Restarting is also possible by running \u003ccode\u003e/etc/init.d/myservice restart\u003c/code\u003e.\n\nVerify the running of the daemon by checking the contents of the created PID file: \u003ccode\u003ecat /var/run/myservice.pid\u003c/code\u003e — It should contain a process ID.\n\n## Run PHP without browser\n\n\nYou can run PHP Script from Linux terminal without the need of any browser. Run the PHP file located at \u003ccode\u003e/var/www/html/infophp.php\u003c/code\u003e in Linux Command Line as\n\n```bash\nphp -f /var/www/html/infophp.php | less\n```\n\nOr\n\n```bash\nphp -f /var/www/html/infophp.php\n```\n\nHere option \u003ccode\u003e-f\u003c/code\u003e parse and execute the file that follows the command.\n\n\n## Run PHP executable\n\nYou can run a PHP script simply as, if it is a shell script. First Create a PHP sample script in your current working directory.\n\n```bash\necho -e '#!/usr/bin/php\\n\u003c?php phpinfo(); ?\u003e' \u003e phpscript.php\n```\n\nNotice we used \u003ccode\u003e#!/usr/bin/php\u003c/code\u003e in the first line of this PHP script as we use to do in shell script \u003ccode\u003e(/bin/bash)\u003c/code\u003e. The first line \u003ccode\u003e#!/usr/bin/php\u003c/code\u003e tells the Linux Command-Line to parse this script file to PHP Interpreter.\n\nSecond make it executable as\n\n```shell\nchmod 755 phpscript.php\n```\n\nand run it as,\n\n```shell\n./phpscript.php\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftankibaj%2Fphp-daemon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftankibaj%2Fphp-daemon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftankibaj%2Fphp-daemon/lists"}