Download the PHP package byjg/php-daemonize without Composer
On this page you can find all versions of the php package byjg/php-daemonize. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download byjg/php-daemonize
More information about byjg/php-daemonize
Files in byjg/php-daemonize
Package php-daemonize
Short Description Transform any class in a *nix daemon process or cron job without changes or refactoring.
License MIT
Informations about the package php-daemonize
PHP Daemonize
Transform any class in a *nix daemon process or cron job without changes or refactoring.
Motivation
Some times we need to create a cron tab or a process for running in background. The most of times we need to create a new class, probably in a different framework and have to set or even choose another language for create the job/daemon.
"Daemonize" enables you to can create a linux daemon or a job for use in a cron tab without change you pre-existing class.
"Daemonize" is a script that create a "init.d" script and encapsulate or class enabling you to run it in the bash, for example.
How to
Suppose you have a pre-existing class for read some info from database and run some action with these data. For example:
If you want transform this class and method in a linux daemon (or "daemonize" it) you have to first create a bootstrap php file.
The most simple bootstrap is vendor/autoload.php
but you can create a more complex bootstrap file if you need.
Below is an example of a bootstrap file:
Now, if you want to test it you can run the command:
You can test with:
If everything is ok, now you can "daemonize" this class (as root):
note: valid templates are:
- systemd (default)
- upstart
- initd
- crond
Now for start or stop the service you need only
For uninstall just type:
and list all "daemonized" php classes
Install
Daemonize does not need to be associated to your PHP project. You can either as a global package or as a local package.
If you want to share this installation with another users consider use the command chmod a+x /root
. The root
directory will remain unreadable for them, but you'll can execute the script "daemonize".
Running a pre-installed demo
Open two terminals.
First do :
On the second do:
If everything is OK, will see on the first terminal a lot of lines added. Do not forget to run sudo service tryme stop