workerman搞崩服务器系列

<?php

use WorkermanWorker;

use WorkermanConnectionAsyncTcpConnection;

require_once __DIR__.'/workerman/Autoloader.php';

$task = new Worker();

// 进程启动时异步建立一个到www.baidu.com连接对象,并发送数据获取数据

$task->onWorkerStart = function($task)

{

for($i=0;$i<256;$i++){

doAsync();}

};

function doAsync(){

// 不支持直接指定http,但是可以用tcp模拟http协议发送数据

$conn = new AsyncTcpConnection('tcp://www.ljwei.com.cn:80');

// 当连接建立成功时,发送http请求数据

$conn->onConnect = function($conn)

{

echo "创建连接 ";

$conn->send("GET / HTTP/1.1 Host:www.ljwei.com.cn Connection: keep-alive ");

};

$conn->onMessage = function($conn, $http_buffer)

{

echo "异步内容内容 ";

$conn->close();

};

$conn->onClose = function($conn)

{

echo "关闭连接 ";

doAsync();

echo "重新创建连接 ";

};

$conn->onError = function($conn, $code, $msg)

{

echo "发生错误 ";

$conn->close();

echo "重新创建连接 ";

};

$conn->connect();

}

// 运行worker

Worker::runAll();


上一篇:ES6 Class 类
下一篇:http报文视图
TOP