~~~
<?php
use \Workerman\Worker;
use \Workerman\Lib\Timer;
require_once '/workerman-for-win/Autoloader.php'; //__DIR__ . '/Workerman/Autoloader.php';
//
require_once('class/mysql.class.php');
$db001 = new class_mysql();
//require_once('class/weixin.class.php');
//$weixin01 = new class_weixin();
// 普通的函数
function send01message01($to, $content)
{
echo '<br/';
echo 'get Here0000000000000000000000000000000';
echo 'send01message01:';
var_dump($to); echo '<br/>';
var_dump($content);
}//// 普通的函数 //function send01message01($to, $content)
function send_m2message01($to, $content)
{
echo "send mail ...\n";
var_dump($to); echo '<br/>';
require_once('class/weixin.class.php');
$weixin01 = new class_weixin();
//
$db012 = new class_mysql();
$mysql_stat01e = "SELECT `id`,`openid`,`heartbeat` FROM `b1r_user` WHERE true " ; //`heartbeat` > ". (time() - 172800); //$mysql_state = "SELECT `id`,`openid`,`heartbeat` FROM `tp_user` WHERE `heartbeat` > ". (time() - 172800);
echo $mysql_stat01e;
$resu01 = $db012->fetch_array($mysql_stat01e); //$result = $db->query($mysql_state);
echo( count($resu01) );
for($j = 0; $j < count($resu01); $j++)
{
echo 'RunHere000000000001';
$openid = $resu01[$j]["openid"];
$resu02lt = $weixin01->send_custom_message($openid, "text", $content); //$resu02lt = $weixin01->send_custom_message($openid, "news", $content);
}
//
}//function send_m2message01($to, $content)
$task = new Worker();
$task->onWorkerStart = function($task) //这里是 下面定义匿名函数:
{
$to = 'workerman@workerman.net';
$content = 'hello workerman001';
// 1(10)秒后执行发送邮件任务,最后一个参数传递true,反复运行;false,表示只运行一次
Timer::add( 1, 'send_m2message01', array($to, $content), true) ; //Timer::add( 1, 'send_mail', array($to, $content), true) ; //持续运行(常驻内存)! //false);
};//Endof: $task->onWorkerStart = function($task)
//
//
//-查mysql中的配置,需要初始化内存(redis或memcached吗?)
$mysql_stat0e01 = "SELECT * from `b1r_timetablemessag1c` "; //`id`,`openid`,`heartbeat` FROM `b1r_user` WHERE true " ; //`heartbeat` > ". (time() - 172800); //$mysql_state = "SELECT `id`,`openid`,`heartbeat` FROM `tp_user` WHERE `heartbeat` > ". (time() - 172800);
echo $mysql_state;
$resu001= $db001->fetch_array_one( $mysql_stat0e01);
var_dump($resu001);
if( 1== $resu001['flag18whether1readmysq01'] ) { //需要读mysql 进内存(redis)
$redi01s = new \Redis();
// 初始化内存中的 配置项目: //$con2config01_isHaveChange= $dat02b[0]['flag18ishave03change01']; //$dat01a[0]['flag18ishave03change01'];
//$con2config01_needPersistent= $dat02b[0]['flag18need03persistent01'];
//$redis->set('flag_isHaveChange', '1');
//$redis->set('con2config01_needPersistent',$con2config01_needPersistent);
//初始化内存中的 TimeTable 时间日程表
$redi01s->connect('127.0.0.1', 6379);
// $redi01s->auth('password'); // Redis 没设置密码则不需要这行代码
$mysql_stat0e02 = "SELECT * from `b1r_timetablemessage` ";
$resu002= $db001->fetch_array( $mysql_stat0e02) ;
var_dump($resu002);
//if(null != $resu002) { //如果获取到 数据库mysql中的值
$redi01s->delete('lis_id');
$redi01s->delete('lis_title');
$redi01s->delete('lis_stat1send');
$redi01s->delete('lis_send1ts');
$redi01s->delete('lis_Stat1send');
$redi01s->delete('lis_pre1next2send1timestamp');
//
foreach( $resu002 as $k1=>$v1) {
$redi01s->rPush('lis_id', $v1['Id']);
$redi01s->rPush('lis_title', $v1['send1title']);
$redi01s->rPush('lis_Stat1send' ,$v1['stat1send']);
echo $v1['stat1send'];
$redi01s->rPush('lis_send1ts', $v1['send1timestamp']);
$redi01s->rPush('lis_pre1next2send1timestamp', $v1['pre1next2send1timestamp']);
$redi01s->rPush('lis_stat1send', $v1['stat1send']);
}//foreach( $conten01t as $k1 $v1
//
//}//if(null != $resu002)
}//if( 1== $resu001['flag18whether1readmysq01'] )
//
//
// 运行worker
Worker::runAll();
~~~