Download the PHP package rogerthomas84/daemoniser without Composer
On this page you can find all versions of the php package rogerthomas84/daemoniser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rogerthomas84/daemoniser
More information about rogerthomas84/daemoniser
Files in rogerthomas84/daemoniser
Package daemoniser
Short Description Daemoniser is a PHP library to help make daemon applications
License MIT
Homepage https://github.com/rogerthomas84/daemoniser
Informations about the package daemoniser
What is it
Daemoniser is a PHP library to take the stress off of creating PHP based daemons. If you're questioning why then this library isn't for you. Generally PHP shouldn't be used for creating daemons.
Use it with Composer
$ composer require rogerthomas84/daemoniser
How to use
For help writing your first daemon, see the example in example/example.php
.
A daemon requires an instance of DaemonConfig
to be passed in via the execute
method.
DaemonConfig constructor:
1) DaemonAbstract $damon
/ The instance of your daemon (which extends DaemonAbstract
)
- Required
2)
$errorLogFilePath
/ A full path to either a new or existing log file to use for logging errors. - Optional, defaults to
tmp/log/error_My_Class_Name.log
(assuming fully qualified class name is\My\Class\Name
) 3)$infoLogFilePath
/ A full path to either a new or existing log file to use for logging echo'd content. - Optional, defaults to
tmp/log/info_My_Class_Name.log
(assuming fully qualified class name is\My\Class\Name
) 4)$pidFilePath
/ A full path to either a new or existing file to use for storing the pid of the dameon'd instance. - Optional, defaults to
tmp/pid/My_Class_Name.pid
(assuming fully qualified class name is\My\Class\Name
) 5)$softStopFilePath
/ The path to the soft stop file. - Optional, defaults to
tmp/stops/stop_My_Class_Name.log
(assuming fully qualified class name is\My\Class\Name
) 6)$sleepDuration
/ How long to sleep after each call to yourrun()
method. - Optional, defaults to
5
seconds 7)$maxLogFileSize
/ How large in bytes should your log file be allowed to get before - Optional, defaults to
100000000
bytes, (100 MB) 8)$iniSettings
/ A key => value array of settings to use withini_set
. For example,['memory_limit' => '1024MB']
- Optional, defaults to empty array
8)
$whitelistedUsers
/ An array containing the usernames allowed to execute this command. - Optional, defaults to empty array, allowing any user.
All config options are also available set
and get
methods in the config object.
Usage
Daemoniser has several helpful commands.
1) php my-daemon.php status
- Get the status of the daemon
2) php my-daemon.php start
- Start the daemon
3) php my-daemon.php soft-stop
- Stop the daemon via a stop file gracefully.
4) php my-daemon.php stop
- Stop the daemon immediately (this is not ideal)
5) php my-daemon.php restart
- Restart the daemon (this is not ideal)
6) php my-daemon.php pid
- Get the PID for the daemon
7) php my-daemon.php rm-logs
- Delete historic logs for this daemon.
8) php my-daemon.php rm-logs all
- Delete ALL logs for this daemon.
9) php my-daemon.php help
- Show the help content
You shouldn't ever use stop
really. Doing so will result in the process being immediately killed. But this is less
of a problem if you aren't running something that could result in data loss in the case of an immediate halt being
called.
If you 'must' have an immediate stop, you'll have to implement the canImmediatelyStop()
method in your daemons
and return true
. This should be avoided at all costs, as the stop process simply kills the pid
immediately.
Extending the commands:
You can easily extend the commands to perform different actions outside of the run()
loop. To do this, simply
implement the protected function getAdditionalCommands()
method.
You'd need to return an array of objects. Each object being an instance of DaemonCommand
. There's a helpful
::build()
method available on the DaemonCommand
which you can use to easily build new functionality.
Should I even use this?
If you're asking yourself this question, then the answer is no. No you shouldn't. This library fills very specific requirements.
Full example file:
All versions of daemoniser with dependencies
ext-pcntl Version *
ext-posix Version *