2017 © Pedro PelĂĄez
 

library php-daemon

Bring workers to your web projects using PHP!

image

adrian0350/php-daemon

Bring workers to your web projects using PHP!

  • Friday, February 9, 2018
  • by adrian0350
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 9 % Grown

The README.md

Introduction

With PHPDaemon you'll be able to run simple one-time daemons in any case you find yourself in a situation where you need to run an external script, meaning you need a Helper in your web project or what not., (*1)

This class works by storing a pid inside your script's dir as .script_file.pid (files starting wiht . are hidden by default)., (*2)

Script output (logging) will be set in $options with the keys (boolean) log and (string) log_path., (*3)

If log is set to true and no log_path is provided or is invalid it will log in the script's directory., (*4)

If log is set to true and log_path is provided and valid it will log into the given log_path., (*5)

Log's name will be your script_file name ending with .log., (*6)

Example: For the pid /your/daemon/path/to/script_file.php would be /your/daemon/path/to/.script_file.php.pid and for the log /your/daemon/path/to/script_file.php without a log_path, it would be /your/daemon/path/to/script_file.php.log., (*7)

PHP Version

This class is compatible with PHP 5.4 and above due to the use of namespaces and PHP_BINARY constant., (*8)

Installing

Add this library to your composer configuration. In composer.json:, (*9)

  "require": {
    "adrian0350/php-daemon": "1.*"
  }

OR

If you're using bash., (*10)

$ composer require adrian0350/php-daemon

Usage

For usage just call the methods from your PHPDaemon instance object., (*11)

<?php

// Start by including the class (if 1 level down).
include_once dirname(__FILE__).'/lib/PHPDaemon.php';

Usage — instantiating

Prepare three arguments you'll need. * Script's compatible binary file path [OPTIONAL]. * Daemon script file path., (*12)

/**
 * Binary file path (per se) [OPTIONAL].
 *  · php
 *  · bash
 *
 * You could run '$ which php' in console
 * and get binary's filepath or use PHP's (^5.4) constant PHP_BINARY (although it's already being used internally).
 *
 * @var string $binary Binary filepath.
 */
$binary = '/opt/local/bin/php';

/**
 * The daemonized † filepath & filename.
 *
 * @var string $script Filepath & filename.
 */
$script = dirname(__FILE__).'/daemon/test.php';

/**
 * Logging options.
 *
 * @var array $options Includes log & log_path.
 */
$options = array(
    'log' => true,
    'log_path' => '/your/log/path'
);

// Instance receives 3 arguments (binary as optional).
$PHPDaemon = new PHPDaemon\PHPDaemon($script, $options, $binary);

Usage — instance handling

if ($PHPDaemon->isAlive())
{
    echo mb_convert_encoding('&#x1F608;', 'UTF-8', 'HTML-ENTITIES');
    echo ' Your daemon is alive and running!'.PHP_EOL;
}
else
{
    if ($PHPDaemon->start())
    {
        echo 'You\'ve unleashed the beast!'.PHP_EOL;
    }
    else
    {
        echo $PHPDaemon->error['message'].PHP_EOL;
    }
}

Usage — stoping daemonized scripts

if ($PHPDaemon->stop())
{
    echo mb_convert_encoding('&#x1F608;', 'UTF-8', 'HTML-ENTITIES');
    echo ' Your daemon has been stopped from deminishing the world!'.PHP_EOL;
}
else
{
    // Print out error message.
    echo $PHPDaemon->error['message'];
}

The Versions

09/02 2018

dev-master

9999999-dev https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Jaime ZĂșñiga

php daemon script

09/02 2018

1.3.4

1.3.4.0 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jaime ZĂșñiga

php daemon script

26/09 2017

dev-php5

dev-php5 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jaime ZĂșñiga

php daemon script

26/09 2017

1.3.3

1.3.3.0 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jaime ZĂșñiga

php daemon script

26/09 2017

1.3.2

1.3.2.0 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jaime ZĂșñiga

php daemon script

25/09 2017

1.3.1

1.3.1.0 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jaime ZĂșñiga

php daemon script

25/09 2017

1.3.0

1.3.0.0 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jaime ZĂșñiga

php daemon script

23/09 2017

1.2.0

1.2.0.0 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jaime ZĂșñiga

php daemon script

23/09 2017

1.0.3

1.0.3.0 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

php daemon script

23/09 2017

1.0.2

1.0.2.0 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

php daemon script

23/09 2017

1.0.1

1.0.1.0 https://github.com/Adrian0350/PHPDaemon

Bring workers to your web projects using PHP!

  Sources   Download

MIT

The Requires

  • php >=5.0

 

by Jaime ZĂșñiga

php daemon script