Download the PHP package apolinux/daemon without Composer

On this page you can find all versions of the php package apolinux/daemon. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package daemon

Process and Daemon manager

Create system daemons process. A daemon program is a special system program that executes in background, where all input data is avoided and output is saved in log files or similar.

This class lets to control the start and stop of the daemon programs and other commands related to the daemon too. It can see the status to check if it is running. Also lets to run the program in foreground to see any problem with code.

Details

The program to be daemonized can be one of the following:

  1. a function called once
  2. a function called repeatedly in a loop
  3. a function called once using system fork
  4. a command line program running once with pcntl_exec
  5. a command line program running once with pcntl_exec and fork
  6. a command line program running in a loop with pcntl_exec and fork

Explanation

The child processes can be called from an anonymous function, an existent function or using a php script.

Example

Running a daemon task once

code:

<?php
use Apolinux\DaemonAdmin\DaemonAdmin;
use Apolinux\DaemonAdmin\TaskManager;

require __DIR__ .'/../vendor/autoload.php' ;

$procname = substr(basename(__FILE__), 0, -4);

$daemon = new DaemonAdmin([
  'pid_file' => __DIR__ ."/var/$procname.pid" ,
  'log_dir' => __DIR__ ."/var"  ,
  'name' => $procname ,
  'task_mode' => TaskManager::MODE_ONCE_CALL ,
  'task' => 'testTask'
]);

function testTask(){
    while(1){
    echo "start task\n" ;
    $f = tmpfile();
    for($i=1 ; $i<=40000; $i++){
       fwrite($f, md5(base64_decode(random_bytes(256)))) ;
    }
    echo "file created\n" ;
    fseek($f,0) ;
    while(! feof($f)){
        $null = fgetc($f);
        unset($null);
    }
    fclose($f);
    echo "file closed\n" ;
    }
}

$daemon->run();

example of use:

>php examples/DaemonTestOnceCall.php 

DaemonTestOnceCall Daemon
Runs a process in background and controlls it
Usage: DaemonTestOnceCall.php  start|stop|restart|status|help|h
  start  : starts the daemon
  stop   : stops the daemon
  restart: stop, then restart daemon
  status : shows daemon info if it is running
  fg     : start in foreground, no daemon                
  help,h : shows this help

>php examples/DaemonTestOnceCall.php start
Starting Daemon
Daemon started

>php examples/DaemonTestOnceCall.php status
process is running with pid: 28572

>php examples/DaemonTestOnceCall.php restart
Stopping daemon
Daemon stopped
Starting Daemon
Daemon started

>php examples/DaemonTestOnceCall.php stop
Stopping daemon
Daemon stopped

>php examples/DaemonTestOnceCall.php status
process is not running

>php examples/DaemonTestOnceCall.php fg
[ 2020-03-23 21:57:00.5051 ] Child started with pid:29144
start task
file created
file closed
start task
file created
file closed
start task
file created
^C

Example list


All versions of daemon with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package apolinux/daemon contains the following files

Loading the files please wait ...