qlg.tsgz.moe/vendor/swoole/tests/swoole_event/swoole_event_set.phpt
2019-09-06 23:53:10 +08:00

49 lines
1008 B
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--TEST--
global_function: swoole_event_set
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--INI--
assert.active=1
assert.warning=1
assert.bail=0
assert.quiet_eval=0
--FILE--
<?php
require_once __DIR__ . '/../include/bootstrap.php';
$fp = stream_socket_client("tcp://www.qq.com:80", $errno, $errstr, 30);
function write_callback($fp) {
$resp = fread($fp, 8192);
//socket处理完成后从epoll事件中移除socket
swoole_event_del($fp);
fclose($fp);
echo "read_callback:SUCCESS\n";
}
swoole_event_add($fp, function($fp) {
$resp = fread($fp, 8192);
//socket处理完成后从epoll事件中移除socket
swoole_event_del($fp);
fclose($fp);
echo "SUCCESS\n";
});
#设置写事件回调函数,这会替换掉原有的写事件回调函数
swoole_event_set($fp, null, 'write_callback', SWOOLE_EVENT_WRITE);
swoole_event_write($fp, "GET / HTTP/1.1\r\nHost: www.qq.com\r\n\r\n");
echo "Finish";
?>
--EXPECT--
Finish
read_callback:SUCCESS