PHP简单定时器可以通过pcntl_signal创建闹钟信号来实现。但是缺点很明显,性能一般,要自己实现守护进程,不支持毫秒级定时器,单进程不支持多个闹钟信号,不能跨平台运行
event扩展支持的事件多,性能高。
<?php
//创建event配置.[空配置]
$eventConfig = new EventConfig();
//创建eventBase对象.event的所有基础类
$eventBase = new EventBase($eventConfig);
//创建event事件
$event = new Event($eventBase,-1,Event::TIMEOUT | Event::PERSIST,function(){
echo 'date:'.date('Y-m-d H:i:s').PHP_EOL;
});
//将创建的event事件扔到eventBase中,并设置超时时间为0.5秒
$event->add(0.05);
//让eventBase对象开始进入事件循环
$eventBase->loop();上面的代码中可以创建多个event事件全部扔到EventBase对象中全部添加到事件循环,同时启动多个定时任务,且事件循环自动阻塞程序不退出。
//$ak开发密钥,$cityname城市名称(支持省县乡详细地址) public function getposition($ak,$cityname){ $callback=array('lng'=>0,'l...
项目需要使用websocket推送最新订单,客户服务器非linux不支持swoole,因此使用原生,直接上代码(1).PHP服务端<?php ini_set('error_reporting', E_ALL ^ E_NOTICE); ini_set...
<?php $member = new class { public function getInfo() { ...
今天帮朋友查询wordpress执行超级慢的原因,特此记录开启fpm的慢日志,记录执行超过30秒的脚本request_slowlog_timeout = 30 slowlog = var/log/slow.log查看日志[23-May-2019 17...
经常我们下载国外资源容易被墙,可以通过php脚本获取远程文件流然后输出给我们的浏览器来下载。<?php //设置下载文件的url $url = 'https://mirrors.huaweicloud.com/ubuntukylin/ubuntukylin-19....
//设置客户端断开依然运行 ignore_user_abort(true); //设置脚本不超时 set_time_limit(0); //死循环每隔1秒访问一次网址 while (true) { sleep(1); &nb...