task schedule php,Autoloader.php

/**

* This file is part of php-task-schedule.

*

* Licensed under The MIT License

* For full copyright and license information, please see the MIT-LICENSE.txt

* Redistributions of files must retain the above copyright notice.

*

* @author liuyin<1053734086@qq.com>

* @copyright liuyin<1053734086@qq.com>

* @link http://www.xxxxxxxx.net/

* @license http://www.opensource.org/licenses/mit-license.php MIT License

*/

namespace TaskSchedule;

/**

* 自动加载类

* @author walkor

* revised by liuyin<1053734086@qq.com>

*/

class Autoloader

{

// 应用的初始化目录,作为加载类文件的参考目录

protected static $_appInitPath = '';

/**

* 设置应用初始化目录

* @param string $root_path

* @return void

*/

public static function setRootPath($root_path)

{

self::$_appInitPath = $root_path;

}

/**

* 根据命名空间加载文件

* @param string $name

* @return boolean

*/

public static function loadByNamespace($name)

{

//var_dump($name);

if(empty(self::$_appInitPath))

{

self::$_appInitPath = __DIR__;

}

// 相对路径

$class_path = str_replace('\\', DIRECTORY_SEPARATOR ,$name);

// 如果不是TaskSchedule命名空间,直接跳出

$baseSpace = 'TaskSchedule\\';

$baseSpaceStrLen = strlen($baseSpace);

if(0 !== strpos($name, $baseSpace))

{

return false;

}

else

{

$class_path = substr($class_path, $baseSpaceStrLen);

$class_file = self::$_appInitPath . DIRECTORY_SEPARATOR . $class_path.'.php';

}

// 找到文件

if(is_file($class_file))

{

// 加载

require_once($class_file);

if(class_exists($name, false))

{

return true;

}

}

return false;

}

}

// 设置类自动加载回调函数

spl_autoload_register('\TaskSchedule\Autoloader::loadByNamespace');

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
taskPHP taskPHP基于php开发的定时计划任务框架,利用多进程实现任务的分配和运行,利用内存共享实现进程间通信,支持多线程模式需要安装pthreads扩展(可选),支持linux和windows。有较好的伸缩性、扩展性、健壮稳定性而被多家公司使用,同时也希望开源爱好者一起贡献。   框架概况 框架目录结构: taskPHP 根目录 |-- core 框架系统目录 | |-- lib 框架核心文件目录 | | |-- .... 众多的框架核心类库文件 | |-- guide.php 框架引导文件 | |-- distribute_listen.php 任务派发进程入口 | |-- worker_listen.php 任务执行进程入口 |-- docs 开发文档存放目录 |-- logs 日志目录 |-- tasks 用户任务目录 | |-- demo demo任务 | | |-- Lib demo任务的扩展目录 | | |-- demoTask.php demo任务类文件 | | |-- config.php demo任务配置文件 | | ... 更多任务 | |-- config.php 全局配置文件 |-- main.php 框架入口文件 |-- windows_single.cmd windows快速启动文件 框架说明 linux下子进程执行任务,修改脚本无需重启后台服务立即生效,windows下修改任务脚本后需重启后台脚本 但往系统添加执行不受影响。 框架支持多线程模式,需要安装pthreads扩展(可选)。 使用内存共享实现进程通信,堵塞式消息队列,整个框架的运行无需第三方扩展。 任务派发及具体任务执行不在同个进程[distribute_listen.php]和[worker_listen.php],windows和linux下启用入口文件[main.php],windows下可运行[windows_single.cmd]快速启动。 执行时间语法跟crontab类似,且支持秒设置。 添加任务简单,只需继承Task基类,实现任务入口run方法。 环境要求 php版本>= 5.5 开启shmop 注意事项 由于任务存在派发时间,所以任务运行的时间可能会有1-2秒的误差。 windows下执行任务在循环里,编写任务有问题或调用exit将导致后台脚本停止,linux下无此问题。 建议生产部署在linux下运行多进程模式,因为运行在多线程模式运行一段时间后报错,pthreads has detected that the core\lib\Pthread could not be started, the system lacks the necessary resources or the system-imposed limit would be exceeded in xxx 文档列表 -->数据库类使用教程 支持(Mysql,Mongo,Oracle,Pgsql,Sqlsrv,Sqllite) -->windows下安装php多线程扩展pthreads教程 -->工具类Utils使用说明 -->http请求客户端类Client使用说明 使用说明 时间配置格式说明: * * * * * * * //格式 :秒 分 时 天 月 年 周 10 * * * * * * //表示每一分钟的第10秒运行 /10 * * * * * * //表示每10秒运行 /1 * 15,16 * * * * //表示 每天的15点,16点的每一秒运行 系统命令说明: main.php [start] 启动 可不带参数 main.php close 结束 main.php reload 重新加载任务 main.php delete demo 删除任务 main.php select 查看任务列表 main.php exec demo 运行任务 主要用于任务开发中调试单个任务 全局配置文件规范 标签:taskphp  计划任务
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值