摘要:在之前的版本中,一直不支持协程化,在代码中无法使用。由于使用了库实现,无法直接它的,版本使用模拟实现了的,并在底层替换了等函数的。跟踪使用跟踪发现,所有系统调用均变成的异步非阻塞调用了。
在4.4之前的版本中,Swoole一直不支持CURL协程化,在代码中无法使用curl。由于curl使用了libcurl库实现,无法直接hook它的socket,4.4版本使用SwooleCoroutineHttpClient模拟实现了curl的API,并在底层替换了curl_init等函数的C Handler。
提示CURL Hook的特性尚处于试验阶段,请勿在生产环境中直接使用
暂不支持文件上传、CURL Multi
仍然需要依赖curl,请务必安装curl扩展
支持的特性列表GET/POST
Header
Cookie
Https
经过验证Guzzle CURL完全可以使用开启
使用Runtime::enableCoroutine来开启CURL Hook。
默认不开启CURL Hook
SwooleRuntime::enableCoroutine(SWOOLE_HOOK_ALL); SwooleRuntime::enableCoroutine(SWOOLE_HOOK_CURL);使用
$n = 10; while($n--) { go(function () { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.xinhuanet.com/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $output = curl_exec($ch); if ($output === FALSE) { echo "CURL Error:" . curl_error($ch); } curl_close($ch); echo strlen($output) . " bytes "; }); }
要将上面两段代码合并到一个文件中执行运行结果
htf@LAPTOP-0K15EFQI:~/swoole-src/examples$ time php curl.php 177173 bytes 177173 bytes 177173 bytes 177173 bytes 177173 bytes 177173 bytes 177173 bytes 177173 bytes 177173 bytes 177173 bytes real 0m0.534s user 0m0.031s sys 0m0.297s
可以看到整个程序是并行的,进程没有任何阻塞。
strace 跟踪使用strace跟踪发现,所有系统调用均变成epoll+socket的异步非阻塞调用了。
epoll_create(512) = 3 mmap(NULL, 258048, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc038a50000 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc028910000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 4 fcntl(4, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(4, SOL_TCP, TCP_NODELAY, [1], 4) = 0 pipe([5, 6]) = 0 fcntl(5, F_GETFL) = 0 (flags O_RDONLY) fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0 fcntl(6, F_GETFL) = 0x1 (flags O_WRONLY) fcntl(6, F_SETFL, O_WRONLY|O_NONBLOCK) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 5, {EPOLLIN, {u32=5, u64=34359738373}}) = 0 mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fc028100000 mprotect(0x7fc028101000, 8388608, PROT_READ|PROT_WRITE) = 0 clone(child_stack=0x7fc0288ffb70, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fc0289009d0, tls=0x7fc028900700, child_tidptr=0x7fc0289009d0) = 55 mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fc0237f0000 mprotect(0x7fc0237f1000, 8388608, PROT_READ|PROT_WRITE) = 0 clone(child_stack=0x7fc023fefb70, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fc023ff09d0, tls=0x7fc023ff0700, child_tidptr=0x7fc023ff09d0) = 56 mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fc022fe0000 mprotect(0x7fc022fe1000, 8388608, PROT_READ|PROT_WRITE) = 0 clone(child_stack=0x7fc0237dfb70, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fc0237e09d0, tls=0x7fc0237e0700, child_tidptr=0x7fc0237e09d0) = 57 mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fc0227d0000 mprotect(0x7fc0227d1000, 8388608, PROT_READ|PROT_WRITE) = 0 clone(child_stack=0x7fc022fcfb70, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fc022fd09d0, tls=0x7fc022fd0700, child_tidptr=0x7fc022fd09d0) = 58 futex(0x7fffd9e01ce0, FUTEX_WAKE_PRIVATE, 1) = 1 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=513190000}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=513408000}) = 0 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0225c0000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 8 fcntl(8, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(8, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(8, SOL_TCP, TCP_NODELAY, [1], 4) = 0 futex(0x7fffd9e01ce0, FUTEX_WAKE_PRIVATE, 1) = 1 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=514359000}) = 0 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0223b0000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 10 fcntl(10, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(10, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(10, SOL_TCP, TCP_NODELAY, [1], 4) = 0 futex(0x7fffd9e01ce0, FUTEX_WAKE_PRIVATE, 1) = 1 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=515961000}) = 0 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0221a0000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 9 fcntl(9, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(9, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(9, SOL_TCP, TCP_NODELAY, [1], 4) = 0 futex(0x7fffd9e01ce4, FUTEX_WAKE_PRIVATE, 1) = 1 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=517822000}) = 0 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021f90000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 7 fcntl(7, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(7, SOL_TCP, TCP_NODELAY, [1], 4) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=520138000}) = 0 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021b60000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 11 fcntl(11, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(11, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(11, SOL_TCP, TCP_NODELAY, [1], 4) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=521400000}) = 0 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021950000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 12 fcntl(12, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(12, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(12, SOL_TCP, TCP_NODELAY, [1], 4) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=523446000}) = 0 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021530000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 17 fcntl(17, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(17, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(17, SOL_TCP, TCP_NODELAY, [1], 4) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=524631000}) = 0 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021320000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 18 fcntl(18, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(18, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(18, SOL_TCP, TCP_NODELAY, [1], 4) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=525903000}) = 0 mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021110000 socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 19 fcntl(19, F_GETFL) = 0x80002 (flags O_RDWR|O_CLOEXEC) fcntl(19, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0 setsockopt(19, SOL_TCP, TCP_NODELAY, [1], 4) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=527295000}) = 0 epoll_wait(3, [{EPOLLIN, {u32=5, u64=34359738373}}], 4096, 1000) = 1 read(5, "0T340331377177 ", 1024) = 8 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(8, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=636297000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 8, {EPOLLOUT, {u32=8, u64=38654705672}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=638815000}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) brk(0x7fffd9e19000) = 0x7fffd9e19000 epoll_wait(3, [{EPOLLIN, {u32=5, u64=34359738373}}], 4096, 875) = 1 read(5, " u333331377177 20g341331377177 200W340331377177 ", 1024) = 24 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(4, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=643393000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLOUT, {u32=4, u64=38654705668}}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(9, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=647077000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 9, {EPOLLOUT, {u32=9, u64=38654705673}}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(10, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=648967000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 10, {EPOLLOUT, {u32=10, u64=38654705674}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=649672000}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) epoll_wait(3, [{EPOLLOUT, {u32=8, u64=38654705672}}], 4096, 870) = 1 epoll_ctl(3, EPOLL_CTL_DEL, 8, NULL) = 0 getsockopt(8, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 brk(0x7fffd9e49000) = 0x7fffd9e49000 sendto(8, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 recvfrom(8, 0x7fffd9e28c70, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 8, {EPOLLIN, {u32=8, u64=38654705672}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=655130000}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) epoll_wait(3, [{EPOLLIN, {u32=5, u64=34359738373}}, {EPOLLOUT, {u32=4, u64=38654705668}}, {EPOLLOUT, {u32=9, u64=38654705673}}], 4096, 865) = 3 read(5, "360l341331377177 ", 1024) = 8 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(7, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=657746000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLOUT, {u32=7, u64=38654705671}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL) = 0 getsockopt(4, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 sendto(4, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 brk(0x7fffd9e79000) = 0x7fffd9e79000 recvfrom(4, 0x7fffd9e48c90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=4, u64=38654705668}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 9, NULL) = 0 getsockopt(9, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 sendto(9, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 recvfrom(9, 0x7fffd9e68cb0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 9, {EPOLLIN, {u32=9, u64=38654705673}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=662268000}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) epoll_wait(3, [{EPOLLIN, {u32=5, u64=34359738373}}, {EPOLLOUT, {u32=10, u64=38654705674}}, {EPOLLOUT, {u32=7, u64=38654705671}}], 4096, 859) = 3 read(5, "P~341331377177 320r341331377177 px341331377177 ", 1024) = 24 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(17, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=664547000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 17, {EPOLLOUT, {u32=17, u64=38654705681}}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(11, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=665490000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 11, {EPOLLOUT, {u32=11, u64=38654705675}}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(12, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=667097000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 12, {EPOLLOUT, {u32=12, u64=38654705676}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 10, NULL) = 0 getsockopt(10, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 brk(0x7fffd9ea9000) = 0x7fffd9ea9000 sendto(10, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 recvfrom(10, 0x7fffd9e88cd0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 10, {EPOLLIN, {u32=10, u64=38654705674}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 7, NULL) = 0 getsockopt(7, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 sendto(7, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 brk(0x7fffd9ed9000) = 0x7fffd9ed9000 recvfrom(7, 0x7fffd9ea8cf0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLIN, {u32=7, u64=38654705671}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=670626000}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) epoll_wait(3, [{EPOLLIN, {u32=5, u64=34359738373}}, {EPOLLOUT, {u32=17, u64=38654705681}}, {EPOLLOUT, {u32=11, u64=38654705675}}], 4096, 855) = 3 read(5, "20212341331377177 000204341331377177 ", 1024) = 16 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(19, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=672183000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 19, {EPOLLOUT, {u32=19, u64=38654705683}}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) connect(18, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("123.125.76.136")}, 16) = -1 EINPROGRESS (Operation now in progress) clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=672576000}) = 0 epoll_ctl(3, EPOLL_CTL_ADD, 18, {EPOLLOUT, {u32=18, u64=38654705682}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 17, NULL) = 0 getsockopt(17, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 sendto(17, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 recvfrom(17, 0x7fffd9ec8d10, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 17, {EPOLLIN, {u32=17, u64=38654705681}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 11, NULL) = 0 getsockopt(11, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 brk(0x7fffd9f09000) = 0x7fffd9f09000 sendto(11, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 recvfrom(11, 0x7fffd9ee8d30, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 11, {EPOLLIN, {u32=11, u64=38654705675}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=674303000}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) epoll_wait(3, [{EPOLLOUT, {u32=12, u64=38654705676}}], 4096, 992) = 1 epoll_ctl(3, EPOLL_CTL_DEL, 12, NULL) = 0 getsockopt(12, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 sendto(12, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 brk(0x7fffd9f39000) = 0x7fffd9f39000 recvfrom(12, 0x7fffd9f08d50, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 12, {EPOLLIN, {u32=12, u64=38654705676}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=687389000}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) epoll_wait(3, [{EPOLLOUT, {u32=19, u64=38654705683}}, {EPOLLOUT, {u32=18, u64=38654705682}}], 4096, 984) = 2 epoll_ctl(3, EPOLL_CTL_DEL, 19, NULL) = 0 getsockopt(19, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 sendto(19, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 recvfrom(19, 0x7fffd9f28d70, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 19, {EPOLLIN, {u32=19, u64=38654705683}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 18, NULL) = 0 getsockopt(18, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 brk(0x7fffd9f69000) = 0x7fffd9f69000 sendto(18, "GET / HTTP/1.1 Host: www.xinhua"..., 90, 0, NULL, 0) = 90 recvfrom(18, 0x7fffd9f48d90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 18, {EPOLLIN, {u32=18, u64=38654705682}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=694225000}) = 0 time(NULL) = 1559698600 (2019-06-05T09:36:40+0800) epoll_wait(3, [{EPOLLIN, {u32=4, u64=38654705668}}], 4096, -1) = 1 epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL) = 0 recvfrom(4, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 4096 recvfrom(4, 0x7fffd9e48c90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=4, u64=38654705668}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=237, tv_nsec=399093000}) = 0 time(NULL) = 1559698604 (2019-06-05T09:36:44+0800) brk(0x7fffd9f59000) = 0x7fffd9f59000 epoll_wait(3, [{EPOLLIN, {u32=4, u64=38654705668}}], 4096, -1) = 1 epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL) = 0 recvfrom(4, "V{362b423622331350H357313374314s372N325732416 25724H217y376204P3206"..., 65536, 0, NULL, NULL) = 8192 recvfrom(4, 0x7fffd9e48c90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=4, u64=38654705668}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=237, tv_nsec=460756000}) = 0 time(NULL) = 1559698604 (2019-06-05T09:36:44+0800) epoll_wait(3, [{EPOLLIN, {u32=4, u64=38654705668}}], 4096, -1) = 1 epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL) = 0 recvfrom(4, "374346{V311306246|0F276337 370`222247253312306200262~37425020"317233w "..., 65536, 0, NULL, NULL) = 8192 recvfrom(4, 0x7fffd9e48c90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=4, u64=38654705668}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=237, tv_nsec=465855000}) = 0 time(NULL) = 1559698604 (2019-06-05T09:36:44+0800) epoll_wait(3, [{EPOLLIN, {u32=4, u64=38654705668}}], 4096, -1) = 1 epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL) = 0 recvfrom(4, "3442@o36234010240#337=J2=274337201307=3O32434235s7167^"23"..., 65536, 0, NULL, NULL) = 19559 brk(0x7fffd9f99000) = 0x7fffd9f99000 close(4) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc028910000, 2101248) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=237, tv_nsec=479677000}) = 0 time(NULL) = 1559698604 (2019-06-05T09:36:44+0800) epoll_wait(3, [{EPOLLIN, {u32=9, u64=38654705673}}, {EPOLLIN, {u32=7, u64=38654705671}}, {EPOLLIN, {u32=17, u64=38654705681}}, {EPOLLIN, {u32=11, u64=38654705675}}], 4096, -1) = 4 epoll_ctl(3, EPOLL_CTL_DEL, 9, NULL) = 0 recvfrom(9, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 4096 recvfrom(9, 0x7fffd9e68cb0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 9, {EPOLLIN, {u32=9, u64=38654705673}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 7, NULL) = 0 recvfrom(7, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 4096 recvfrom(7, "V{362b423622331350H357313374314s372N325732416 25724H217y376204P3206"..., 65536, 0, NULL, NULL) = 4096 recvfrom(7, 0x7fffd9ea8cf0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLIN, {u32=7, u64=38654705671}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 17, NULL) = 0 recvfrom(17, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 8192 recvfrom(17, 0x7fffd9ec8d10, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 17, {EPOLLIN, {u32=17, u64=38654705681}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 11, NULL) = 0 recvfrom(11, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 8192 recvfrom(11, 0x7fffd9ee8d30, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 11, {EPOLLIN, {u32=11, u64=38654705675}}) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=238, tv_nsec=747275000}) = 0 time(NULL) = 1559698606 (2019-06-05T09:36:46+0800) madvise(0x7fffd9dcd000, 61440, MADV_DONTNEED) = 0 madvise(0x7fffd9e39000, 126976, MADV_DONTNEED) = 0 epoll_wait(3, [{EPOLLIN, {u32=8, u64=38654705672}}, {EPOLLIN, {u32=10, u64=38654705674}}, {EPOLLIN, {u32=12, u64=38654705676}}, {EPOLLIN, {u32=19, u64=38654705683}}, {EPOLLIN, {u32=18, u64=38654705682}}, {EPOLLIN, {u32=9, u64=38654705673}}, {EPOLLIN, {u32=7, u64=38654705671}}, {EPOLLIN, {u32=17, u64=38654705681}}], 4096, -1) = 8 epoll_ctl(3, EPOLL_CTL_DEL, 8, NULL) = 0 recvfrom(8, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 20480 recvfrom(8, 0x7fffd9e28c70, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 8, {EPOLLIN, {u32=8, u64=38654705672}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 10, NULL) = 0 recvfrom(10, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 12288 recvfrom(10, 0x7fffd9e88cd0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 10, {EPOLLIN, {u32=10, u64=38654705674}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 12, NULL) = 0 recvfrom(12, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 20480 recvfrom(12, 0x7fffd9f08d50, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 12, {EPOLLIN, {u32=12, u64=38654705676}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 19, NULL) = 0 recvfrom(19, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 20480 recvfrom(19, 0x7fffd9f28d70, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 19, {EPOLLIN, {u32=19, u64=38654705683}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 18, NULL) = 0 recvfrom(18, "HTTP/1.1 200 OK Content-Type: t"..., 65536, 0, NULL, NULL) = 20480 recvfrom(18, 0x7fffd9f48d90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_ADD, 18, {EPOLLIN, {u32=18, u64=38654705682}}) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 9, NULL) = 0 recvfrom(9, "V{362b423622331350H357313374314s372N325732416 25724H217y376204P3206"..., 65536, 0, NULL, NULL) = 29504 recvfrom(9, "231_243"240C3013764931314255236344f22305_357hojll0FS240 254"..., 65536, 0, NULL, NULL) = 6439 close(9) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc0221a0000, 2101248) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 7, NULL) = 0 recvfrom(7, "32313372375"271e271cZ343bb251331314227323L257224311324335276(D32334124231"..., 65536, 0, NULL, NULL) = 31847 close(7) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc021f90000, 2101248) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 17, NULL) = 0 recvfrom(17, "32313372375"271e271cZ343bb251331314227323L257224311324335276(D32334124231"..., 65536, 0, NULL, NULL) = 31847 close(17) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc021530000, 2101248) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=238, tv_nsec=783851000}) = 0 time(NULL) = 1559698606 (2019-06-05T09:36:46+0800) epoll_wait(3, [{EPOLLIN, {u32=11, u64=38654705675}}, {EPOLLIN, {u32=8, u64=38654705672}}, {EPOLLIN, {u32=10, u64=38654705674}}, {EPOLLIN, {u32=12, u64=38654705676}}, {EPOLLIN, {u32=19, u64=38654705683}}, {EPOLLIN, {u32=18, u64=38654705682}}], 4096, -1) = 6 epoll_ctl(3, EPOLL_CTL_DEL, 11, NULL) = 0 recvfrom(11, "32313372375"271e271cZ343bb251331314227323L257224311324335276(D32334124231"..., 65536, 0, NULL, NULL) = 31847 close(11) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc021b60000, 2101248) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 8, NULL) = 0 recvfrom(8, "3442@o36234010240#337=J2=274337201307=3O32434235s7167^"23"..., 65536, 0, NULL, NULL) = 19559 close(8) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc0225c0000, 2101248) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 10, NULL) = 0 recvfrom(10, "374346{V311306246|0F276337 370`222247253312306200262~37425020"317233w "..., 65536, 0, NULL, NULL) = 27751 close(10) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc0223b0000, 2101248) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 12, NULL) = 0 recvfrom(12, "3442@o36234010240#337=J2=274337201307=3O32434235s7167^"23"..., 65536, 0, NULL, NULL) = 19559 close(12) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc021950000, 2101248) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 19, NULL) = 0 recvfrom(19, "3442@o36234010240#337=J2=274337201307=3O32434235s7167^"23"..., 65536, 0, NULL, NULL) = 19559 close(19) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc021110000, 2101248) = 0 epoll_ctl(3, EPOLL_CTL_DEL, 18, NULL) = 0 recvfrom(18, "3442@o36234010240#337=J2=274337201307=3O32434235s7167^"23"..., 65536, 0, NULL, NULL) = 19559 close(18) = 0 write(1, "177115 bytes ", 13) = 13 munmap(0x7fc021320000, 2101248) = 0 clock_gettime(CLOCK_MONOTONIC, {tv_sec=238, tv_nsec=802835000}) = 0 time(NULL) = 1559698606 (2019-06-05T09:36:46+0800) futex(0x7fffd9e01ce0, FUTEX_WAKE_PRIVATE, 2147483647) = 4 futex(0x7fffd9e01c90, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x7fc023ff09d0, FUTEX_WAIT, 56, NULL) = -1 EAGAIN (Resource temporarily unavailable) epoll_ctl(3, EPOLL_CTL_DEL, 5, NULL) = 0 close(5) = 0 close(6) = 0 close(2) = 0 close(1) = 0 close(0) = 0 munmap(0x7fc028fa0000, 2231560) = 0 munmap(0x7fc028d1f000, 2624568) = 0 close(3) = 0
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/31634.html
摘要:之后协程化支持已经完善并且支持大量的扩展自动协程化一些基于的框架也蓬勃发展光看着文档就让人跃跃欲试但是对于现有旧项目如何引入并启用协程成了实际场景中的客观问题由于协程性质及生命周期等原因这并非想象的那么容易本文整理了在现有项目中引入并开启协 Swoole4之后,协程化支持已经完善,并且支持大量的PHP扩展自动协程化.一些基于Swoole4的框架也蓬勃发展,光看着文档就让人跃跃欲试.但是...
摘要:是一个非常流行的的客户端,现在各大厂的也都开始基于开发,因为只支持的协程,而默认是使用扩展的,所以开发了,能在不修改源码的情况下让协程化。 Guzzle 是一个非常流行的 PHP 的 HTTP 客户端,现在各大厂的 SDK 也都开始基于 Guzzle 开发,因为 Swoole 只支持 PHP Stream 的协程 Hook ,而 Guzzle 默认是使用 cURL 扩展的,所以 Mix...
摘要:抢占式调度我们在今年年初就计划实现的抢占式调度,以满足实现有些场景下的不均衡调度带来的问题。考虑开线程,负责检查当前执行协程执行时间。达到我们的第二个协程主动抢占第一个协程的效果。 前言 Swoole内核团队开设的专栏,会逐渐投入精力写文章介绍Swoole的开发历程,实现原理,应用实践等,大家可以更好的交流,共同学习,建设PHP生态。 协程调度 去年Swoole推出了4.0版本后,完整...
摘要:重大新特性支持从版本开始支持了对原生协程化的支持。可使用将普通的同步阻塞操作变为协程调度的异步非阻塞协程跟踪新版本增加了两个方法用于跟踪协程运行。 重大新特性 支持 Redis/PDO/MySQLi 从4.1.0版本开始支持了对PHP原生Redis、PDO、MySQLi协程化的支持。 可使用SwooleRuntime::enableCorotuine()将普通的同步阻塞Redis、PD...
摘要:结语考虑到在国内的流行度并不高,可能帮不了国内的多少开发者,本文只为做一个引导,有兴趣的可以直接查看官方文档获得更多信息,同时还自行实现了更好支持度的静态资源访问支持,有兴趣的也可以了解一下。 前言 Zend Framework 是 PHP 的官方框架,随着 Zend-Expressive-Swoole 0.2.2 的发布,率先支持了 Swoole 4 的协程功能,现在可以仅通过一个配...
阅读 3167·2021-11-23 09:51
阅读 1504·2021-11-22 09:34
阅读 2808·2021-10-27 14:15
阅读 2229·2021-10-12 10:17
阅读 1866·2021-10-12 10:12
阅读 894·2021-09-27 14:00
阅读 1950·2021-09-22 15:19
阅读 978·2019-08-30 10:51