-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share tested classes from live project
- Loading branch information
Showing
5 changed files
with
677 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# PHP multi-OS daemon library | ||
|
||
Create long-running jobs, daemons, self recovering processes for any OS environment | ||
Create long-running jobs, daemons, self recovering processes for any OS environment | ||
|
||
Install library via Composer | ||
------------ | ||
```sh | ||
composer require waldz/php-multios-daemon | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "waldz/php-multios-daemon", | ||
"description": "Create long-running jobs, daemons, self recovering processes for any OS environment", | ||
"license": "MIT", | ||
"keywords": [ | ||
"php", | ||
"daemon", | ||
"cronjob" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Valdas Petrulis", | ||
"email": "petrulis.valdas@gmail.com", | ||
"homepage": "https://lt.linkedin.com/in/valdaspetrulis", | ||
"role": "Architect/Developer/DevOps" | ||
} | ||
], | ||
"type": "library", | ||
"minimum-stability": "stable", | ||
"autoload": { | ||
"psr-4": { | ||
"MultiOSDaemon\\": "src" | ||
} | ||
}, | ||
"require": { | ||
"php": ">=5.3.0" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace MultiOSDaemon; | ||
|
||
/** | ||
* Run any process as a CRON job - run only once in minute and do some job | ||
* | ||
* @package Daemon | ||
* @subpackage Model | ||
* | ||
* @author Valdas Petrulis <petrulis.valdas@gmail.com> | ||
*/ | ||
abstract class CronAbstract | ||
extends DaemonAbstract | ||
{ | ||
|
||
/** | ||
* Daemon object constructor | ||
* | ||
* @param string $pidFile Daemon process id file | ||
* @param string $statusFile Daemon status file | ||
* @param string $logFile Daemon log file | ||
*/ | ||
public function __construct($pidFile, $statusFile, $logFile=null) | ||
{ | ||
parent::__construct($pidFile, $statusFile, $logFile); | ||
|
||
// Run only once in a minute and exit | ||
$this->setCheckTtl(null); | ||
$this->setRestartTtl(0); | ||
|
||
} | ||
|
||
/** | ||
* Configures daemon job before looping | ||
* | ||
* @param array $jobParams | ||
* @return void | ||
*/ | ||
public function init($jobParams = array()) | ||
{ | ||
// Do nothing | ||
} | ||
|
||
/** | ||
* On loop cycle of daemon | ||
* | ||
* @return void | ||
*/ | ||
public function step() | ||
{ | ||
if($this->checkJobTime()) { | ||
$this->doJob(); | ||
} else { | ||
$this->log('CRON time not come yet'); | ||
} | ||
} | ||
|
||
/** | ||
* Check if time has come for job to be run | ||
* | ||
* @return bool | ||
*/ | ||
public function checkJobTime() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* On time then CRON need to be run | ||
* | ||
* @return void | ||
*/ | ||
abstract public function doJob(); | ||
|
||
} |
Oops, something went wrong.