今天在学习thinkphp5.0.24+workman定时器功能的时候,写了一个简单的定时器,定时输出一段文字(环境是window10)。用了\r\n换行输出:
<?php
namespace app\push\controller;
use think\worker\Server;
use Workerman\Lib\Timer;
class MyTimer extends Server{
//定时器
public function add_timer(){
Timer::add(5, array($this, 'index'), array(), true);
}
//执行方法
public function index()
{
file_put_contents("test.txt", "PHP是最好的语言!".date('Y-m-d H:i:s').'\r\n', FILE_APPEND); //每5秒向test.txt写入PHP是最好的语言!
}
}
得到的输出结果:
发现换行符没有起作用,百度了一下,说是要用双引号:"\r\n"
还真是这样: