2017 © Pedro Peláez
 

library crontab

php crontab base on pcntl and libev

image

dragonlhp/crontab

php crontab base on pcntl and libev

  • Friday, February 23, 2018
  • by cnPauLi
  • Repository
  • 0 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

php_crontab

Total Downloads Latest Stable Version License, (*1)

»ùÓÚpcntlºÍreact/event-loopµÄ¶¨Ê±ÈÎÎñ¹ÜÀíÆ÷, (*2)

Ó¢ÎÄ˵Ã÷, (*3)

ΪʲôʹÓÃphp_crontab£¿

µ±ÎÒÃÇÓÐÉÙÁ¿µÄ¶¨Ê±ÈÎÎñÐèÒª¹ÜÀíʱ£¬unixµÄcrontab·þÎñʱ×ã¹»µÄ¡£Èç¹ûÎÒÃÇÓзdz£¶àµÄ¶¨Ê±ÈÎÎñ ÐèÒª¹ÜÀíʱ£¬»ú»áÓÐһЩÎÊÌ⣬ÀýÈ磺 + crontab·þÎñͨ¹ýÒ»¸öÎı¾Îļþ¹ÜÀí¶¨Ê±ÈÎÎñ£¬Èç¹ûûÓÐ×¢ÊÍ£¬¶ÔÐÂÈËÀ´ËµÈ¥Àí½âËûÃÇÊDZȽÏÄѵġ£ + Èç¹û¶¨Ê±ÈÎÎñ·ÖÉ¢ÔÚÐí¶à»úÆ÷ÉÏ£¬¹ÜÀíËûÃÇÒ²ÊDZȽÏÄѵġ£ + Èç¹ûÄãÏëÊÕ¼¯ËûÃǵÄÈÕÖ¾£¬Í¬Ñù²»»á¼òµ¥¡£ + ²»Í¬Óû§µÄ¶¨Ê±ÈÎÎñ·ÖÉ¢ÔÚ²»Í¬µÄÎļþÖС£ »ùÓÚÒÔÉϼ¸µãÔ­Òò£¬ÎÒÃÇÐèÒªÒ»¸ö¿ÉÒÔͳһ¹ÜÀíÅäÖõĶ¨Ê±ÈÎÎñ¹ÜÀíÆ÷¡£, (*4)

ÈçºÎʹÓÃphp_crontab£¿

ÓÐÁ½ÖÖ·½Ê½Ê¹ÓÃphp_crontab¹ÜÀíÄãµÄ¶¨Ê±ÈÎÎñ¡£ Äã¿ÉÒÔдһ¸ö½Å±¾£¬È»ºó°ÑËü¼ÓÈëµ½crontab·þÎñÆ÷ÖУ¬Ã¿·ÖÖÓÖ´ÐÐÒ»´Î¡£ÀýÈçtests/simple¡£ »òÕßÄã¿ÉÒÔдһ¸öÊØ»¤½ø³Ì½Å±¾£¬Ëü»áÏñÒ»¸ö·þÎñÒ»ÑùÒ»Ö»ÔËÐУ¬Ö±µ½ÄãɱËÀËü¡£ Ëü½«Ã¿·ÖÖÓ¼ì²éÒ»´Î¶¨Ê±ÈÎÎñ¡£ÀýÈçtests/daemon.php, (*5)

ÌØÐÔ

  • ¶¨Ê±ÈÎÎñ¹ÜÀí¿ÉÒÔ±»´æ´¢ÔÚÈκεط½¡£ÀýÈ磺mysql¡¢redisµÈ¡£
  • ¶¨Ê±ÈÎÎñµÄÈÕÖ¾¿ÉÒÔ¸ù¾ÝÄãµÄÐèÒª½øÐÐÅäÖÃ
  • ¶à¸öÓû§µÄ¶¨Ê±ÈÎÎñ¿ÉÒÔͳһ¹ÜÀí
  • ¶à½ø³Ì£¬Ã¿¸öÈÎÎñÒ»¸ö½ø³Ì
  • Äã¿ÉÒÔΪÿ¸öÈÎÎñÉèÖÃÓû§ºÍÓû§×é
  • ±ê×¼Êä³ö¿ÉÒÔ½øÐÐÖØ¶¨Ïò
  • »ùÓÚreact/event-loop£¬Ëü¿ÉÒÔ×÷Ϊһ¸öÊØ»¤½ø³ÌÔËÐÐ
  • Ò»¸öHTTP·þÎñÆ÷£¬Äã¿ÉÒÔͨ¹ýËü¹ÜÀí¶¨Ê±ÈÎÎñ

HTTP ½Ó¿Ú

HTTP ·½·¨: GET
+ add Ôö¼ÓÈÎÎñ + get_by_name ¸ù¾ÝÈÎÎñÃû³Æ»ñÈ¡ÈÎÎñ + remove_by_name ¸ù¾ÝÈÎÎñÃû³ÆÉ¾³ýÈÎÎñ + clear ɾ³ýËùÓÐÈÎÎñ + get »ñÈ¡ËùÓÐÈÎÎñ + start ¿ªÊ¼¼ì²â¶¨Ê±ÈÎÎñ + stop Í£Ö¹¼ì²â¶¨Ê±ÈÎÎñ, (*6)

ʾÀý:, (*7)

http://host:port/add?name=name&cmd=cmd&time=time&out=out&user=user&group=group&comment=comment
http://host:port/get_by_name?name=name
http://host:port/remove_by_name?name=name
http://host:port/clear
http://host:port/get
http://host:port/start
http://host:port/stop

»ùÓÚcrontab·þÎñÔËÐÐ, (*8)

* * * * * php demo.php

```php <?php $missions = [ [ 'name' => 'ls', 'cmd' => "ls -al", 'out' => '/tmp/php_crontab.log', 'time' => '* * * * ', 'user' => 'www', 'group' => 'www' ], [ 'name' => 'hostname', 'cmd' => "hostname", 'out' => '/tmp/php_crontab.log', 'time' => ' * * * *', ], ];, (*9)

$tasks = array(); foreach($missions as $mission){ $tasks[] = new \Jenner\Crontab\Mission($mission['name'], $mission['cmd'], $mission['time'], $mission['out']); }, (*10)

$crontab_server = new \Jenner\Crontab\Crontab(null, $tasks); $crontab_server->start(time());, (*11)



×÷ÎªÊØ»¤½ø³ÌÔËÐÐͬʱÆô¶¯Ò»¸öhttp server, (*12)

$missions = [
    [
        'name' => 'ls',
        'cmd' => "ls -al",
        'out' => '/tmp/php_crontab.log',
        'time' => '* * * * *',
    ],
    [
        'name' => 'hostname',
        'cmd' => "hostname",
        'out' => '/tmp/php_crontab.log',
        'time' => '* * * * *',
    ],
];

$http_daemon = new \Jenner\Crontab\HttpDaemon($missions, "php_crontab.log");
$http_daemon->start($port = 6364);

Then you can manage the crontab task by curl like:, (*13)

curl http://127.0.0.1:6364/get_by_name?name=ls
curl http://127.0.0.1:6364/remove_by_name?name=hostname
curl http://127.0.0.1:6364/get

Æô¶¯½Å±¾, (*14)

[root@jenner php_crontab]# ./bin/php_crontab 
php_crontab help:
-c  --config    crontab tasks config file
-p  --port      http server port
-f  --pid-file  daemon pid file
-l  --log       crontab log file
[root@jenner php_crontab]#nohup ./bin/php_crontab -c xxoo.php -p 8080 -f /var/php_crontab.pid -l /var/logs/php_crontab.log >/dev/null & 

blog:www.huyanping.cn, (*15)

The Versions

23/02 2018

dev-master

9999999-dev

php crontab base on pcntl and libev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pauli

crontab crontab manager php crontab

23/02 2018

1.6.2

1.6.2.0

php crontab base on pcntl and libev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pauli

crontab crontab manager php crontab

23/02 2018

v1.6.1

1.6.1.0

php crontab base on pcntl and libev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pauli

crontab crontab manager php crontab

23/02 2018

v1.6

1.6.0.0

php crontab base on pcntl and libev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pauli

crontab crontab manager php crontab

23/02 2018

v1.5.5

1.5.5.0

php crontab base on pcntl and libev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pauli

crontab crontab manager php crontab

23/02 2018

v1.5.3

1.5.3.0

php crontab base on pcntl and libev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pauli

crontab crontab manager php crontab

23/02 2018

v1.5.2

1.5.2.0

php crontab base on pcntl and libev

  Sources   Download

MIT

The Requires

 

The Development Requires

crontab crontab manager php crontab