Swoole 4.4:支持 CURL 协程化

2019年6月6日 315点热度 0人点赞 0条评论

图片

本文原载于SegmentFault专栏“Swoole”

作者:韩天峰

整理编辑:SegmentFault


4.4之前的版本中,Swoole一直不支持CURL协程化,在代码中无法使用curl。由于curl使用了libcurl库实现,无法直接hook它的socket4.4版本使用Swoole\Coroutine\Http\Client模拟实现了curlAPI,并在底层替换了curl_init等函数的C Handler


提示

  • CURL Hook的特性尚处于试验阶段,请勿在生产环境中直接使用

  • 暂不支持文件上传、CURL Multi

  • 仍然需要依赖curl,请务必安装curl扩展


支持的特性列表

  • GET/POST

  • Header

  • Cookie

  • Https

经过验证Guzzle CURL完全可以使用

开启


使用Runtime::enableCoroutine来开启CURL Hook

默认不开启CURL Hook

Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL);Swoole\Runtime::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\n";    });}

要将上面两段代码合并到一个文件中执行


运行结果

htf@LAPTOP-0K15EFQI:~/swoole-src/examples$ time php curl.php177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes177173 bytes
real 0m0.534suser 0m0.031ssys 0m0.297s

可以看到整个程序是并行的,进程没有任何阻塞。


strace 跟踪


使用strace跟踪发现,所有系统调用均变成epoll+socket的异步非阻塞调用了。

epoll_create(512)                       = 3mmap(NULL, 258048, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc038a50000mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc028910000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 4fcntl(4, F_GETFL)                       = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(4, SOL_TCP, TCP_NODELAY, [1], 4) = 0pipe([5, 6])                            = 0fcntl(5, F_GETFL)                       = 0 (flags O_RDONLY)fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK)  = 0fcntl(6, F_GETFL)                       = 0x1 (flags O_WRONLY)fcntl(6, F_SETFL, O_WRONLY|O_NONBLOCK)  = 0epoll_ctl(3, EPOLL_CTL_ADD, 5, {EPOLLIN, {u32=5, u64=34359738373}}) = 0mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fc028100000mprotect(0x7fc028101000, 8388608, PROT_READ|PROT_WRITE) = 0clone(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) = 55mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fc0237f0000mprotect(0x7fc0237f1000, 8388608, PROT_READ|PROT_WRITE) = 0clone(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) = 56mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fc022fe0000mprotect(0x7fc022fe1000, 8388608, PROT_READ|PROT_WRITE) = 0clone(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) = 57mmap(NULL, 8392704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7fc0227d0000mprotect(0x7fc0227d1000, 8388608, PROT_READ|PROT_WRITE) = 0clone(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) = 58futex(0x7fffd9e01ce0, FUTEX_WAKE_PRIVATE, 1) = 1clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=513190000}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=513408000}) = 0mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0225c0000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 8fcntl(8, F_GETFL)                       = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(8, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(8, SOL_TCP, TCP_NODELAY, [1], 4) = 0futex(0x7fffd9e01ce0, FUTEX_WAKE_PRIVATE, 1) = 1clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=514359000}) = 0mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0223b0000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 10fcntl(10, F_GETFL)                      = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(10, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(10, SOL_TCP, TCP_NODELAY, [1], 4) = 0futex(0x7fffd9e01ce0, FUTEX_WAKE_PRIVATE, 1) = 1clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=515961000}) = 0mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc0221a0000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 9fcntl(9, F_GETFL)                       = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(9, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(9, SOL_TCP, TCP_NODELAY, [1], 4) = 0futex(0x7fffd9e01ce4, FUTEX_WAKE_PRIVATE, 1) = 1clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=517822000}) = 0mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021f90000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 7fcntl(7, F_GETFL)                       = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(7, SOL_TCP, TCP_NODELAY, [1], 4) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=520138000}) = 0mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021b60000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 11fcntl(11, F_GETFL)                      = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(11, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(11, SOL_TCP, TCP_NODELAY, [1], 4) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=521400000}) = 0mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021950000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 12fcntl(12, F_GETFL)                      = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(12, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(12, SOL_TCP, TCP_NODELAY, [1], 4) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=523446000}) = 0mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021530000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 17fcntl(17, F_GETFL)                      = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(17, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(17, SOL_TCP, TCP_NODELAY, [1], 4) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=524631000}) = 0mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021320000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 18fcntl(18, F_GETFL)                      = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(18, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(18, SOL_TCP, TCP_NODELAY, [1], 4) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=525903000}) = 0mmap(NULL, 2101248, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc021110000socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 19fcntl(19, F_GETFL)                      = 0x80002 (flags O_RDWR|O_CLOEXEC)fcntl(19, F_SETFL, O_RDWR|O_NONBLOCK|O_CLOEXEC) = 0setsockopt(19, SOL_TCP, TCP_NODELAY, [1], 4) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=527295000}) = 0epoll_wait(3, [{EPOLLIN, {u32=5, u64=34359738373}}], 4096, 1000) = 1read(5, "0T\340\331\377\177\0\0", 1024) = 8time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 8, {EPOLLOUT, {u32=8, u64=38654705672}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=638815000}) = 0time(NULL)                              = 1559698600 (2019-06-05T09:36:40+0800)brk(0x7fffd9e19000)                     = 0x7fffd9e19000epoll_wait(3, [{EPOLLIN, {u32=5, u64=34359738373}}], 4096, 875) = 1read(5, "\0u\333\331\377\177\0\0\20g\341\331\377\177\0\0\200W\340\331\377\177\0\0", 1024) = 24time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLOUT, {u32=4, u64=38654705668}}) = 0time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 9, {EPOLLOUT, {u32=9, u64=38654705673}}) = 0time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 10, {EPOLLOUT, {u32=10, u64=38654705674}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=649672000}) = 0time(NULL)                              = 1559698600 (2019-06-05T09:36:40+0800)epoll_wait(3, [{EPOLLOUT, {u32=8, u64=38654705672}}], 4096, 870) = 1epoll_ctl(3, EPOLL_CTL_DEL, 8, NULL)    = 0getsockopt(8, SOL_SOCKET, SO_ERROR, [0], [4]) = 0brk(0x7fffd9e49000)                     = 0x7fffd9e49000sendto(8, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90recvfrom(8, 0x7fffd9e28c70, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 8, {EPOLLIN, {u32=8, u64=38654705672}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=655130000}) = 0time(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) = 3read(5, "\360l\341\331\377\177\0\0", 1024) = 8time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLOUT, {u32=7, u64=38654705671}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL)    = 0getsockopt(4, SOL_SOCKET, SO_ERROR, [0], [4]) = 0sendto(4, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90brk(0x7fffd9e79000)                     = 0x7fffd9e79000recvfrom(4, 0x7fffd9e48c90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=4, u64=38654705668}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 9, NULL)    = 0getsockopt(9, SOL_SOCKET, SO_ERROR, [0], [4]) = 0sendto(9, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90recvfrom(9, 0x7fffd9e68cb0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 9, {EPOLLIN, {u32=9, u64=38654705673}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=662268000}) = 0time(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) = 3read(5, "P~\341\331\377\177\0\0\320r\341\331\377\177\0\0px\341\331\377\177\0\0", 1024) = 24time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 17, {EPOLLOUT, {u32=17, u64=38654705681}}) = 0time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 11, {EPOLLOUT, {u32=11, u64=38654705675}}) = 0time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 12, {EPOLLOUT, {u32=12, u64=38654705676}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 10, NULL)   = 0getsockopt(10, SOL_SOCKET, SO_ERROR, [0], [4]) = 0brk(0x7fffd9ea9000)                     = 0x7fffd9ea9000sendto(10, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90recvfrom(10, 0x7fffd9e88cd0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 10, {EPOLLIN, {u32=10, u64=38654705674}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 7, NULL)    = 0getsockopt(7, SOL_SOCKET, SO_ERROR, [0], [4]) = 0sendto(7, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90brk(0x7fffd9ed9000)                     = 0x7fffd9ed9000recvfrom(7, 0x7fffd9ea8cf0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLIN, {u32=7, u64=38654705671}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=670626000}) = 0time(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) = 3read(5, "\20\212\341\331\377\177\0\0000\204\341\331\377\177\0\0", 1024) = 16time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 19, {EPOLLOUT, {u32=19, u64=38654705683}}) = 0time(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}) = 0epoll_ctl(3, EPOLL_CTL_ADD, 18, {EPOLLOUT, {u32=18, u64=38654705682}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 17, NULL)   = 0getsockopt(17, SOL_SOCKET, SO_ERROR, [0], [4]) = 0sendto(17, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90recvfrom(17, 0x7fffd9ec8d10, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 17, {EPOLLIN, {u32=17, u64=38654705681}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 11, NULL)   = 0getsockopt(11, SOL_SOCKET, SO_ERROR, [0], [4]) = 0brk(0x7fffd9f09000)                     = 0x7fffd9f09000sendto(11, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90recvfrom(11, 0x7fffd9ee8d30, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 11, {EPOLLIN, {u32=11, u64=38654705675}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=674303000}) = 0time(NULL)                              = 1559698600 (2019-06-05T09:36:40+0800)epoll_wait(3, [{EPOLLOUT, {u32=12, u64=38654705676}}], 4096, 992) = 1epoll_ctl(3, EPOLL_CTL_DEL, 12, NULL)   = 0getsockopt(12, SOL_SOCKET, SO_ERROR, [0], [4]) = 0sendto(12, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90brk(0x7fffd9f39000)                     = 0x7fffd9f39000recvfrom(12, 0x7fffd9f08d50, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 12, {EPOLLIN, {u32=12, u64=38654705676}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=687389000}) = 0time(NULL)                              = 1559698600 (2019-06-05T09:36:40+0800)epoll_wait(3, [{EPOLLOUT, {u32=19, u64=38654705683}}, {EPOLLOUT, {u32=18, u64=38654705682}}], 4096, 984) = 2epoll_ctl(3, EPOLL_CTL_DEL, 19, NULL)   = 0getsockopt(19, SOL_SOCKET, SO_ERROR, [0], [4]) = 0sendto(19, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90recvfrom(19, 0x7fffd9f28d70, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 19, {EPOLLIN, {u32=19, u64=38654705683}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 18, NULL)   = 0getsockopt(18, SOL_SOCKET, SO_ERROR, [0], [4]) = 0brk(0x7fffd9f69000)                     = 0x7fffd9f69000sendto(18, "GET / HTTP/1.1\r\nHost: www.xinhua"..., 90, 0, NULL, 0) = 90recvfrom(18, 0x7fffd9f48d90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 18, {EPOLLIN, {u32=18, u64=38654705682}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=232, tv_nsec=694225000}) = 0time(NULL)                              = 1559698600 (2019-06-05T09:36:40+0800)epoll_wait(3, [{EPOLLIN, {u32=4, u64=38654705668}}], 4096, -1) = 1epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL)    = 0recvfrom(4, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 4096recvfrom(4, 0x7fffd9e48c90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=4, u64=38654705668}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=237, tv_nsec=399093000}) = 0time(NULL)                              = 1559698604 (2019-06-05T09:36:44+0800)brk(0x7fffd9f59000)                     = 0x7fffd9f59000epoll_wait(3, [{EPOLLIN, {u32=4, u64=38654705668}}], 4096, -1) = 1epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL)    = 0recvfrom(4, "V{\362b4\236\22\331\350H\357\313\374\314s\372N\3257\324\16\n\257\24H\217y\376\204P\3\206"..., 65536, 0, NULL, NULL) = 8192recvfrom(4, 0x7fffd9e48c90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=4, u64=38654705668}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=237, tv_nsec=460756000}) = 0time(NULL)                              = 1559698604 (2019-06-05T09:36:44+0800)epoll_wait(3, [{EPOLLIN, {u32=4, u64=38654705668}}], 4096, -1) = 1epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL)    = 0recvfrom(4, "\374\346{V\311\306\246|0F\276\337\0\370`\22\224\7\253\312\306\200\262~\374\250\20'\317\233w\r"..., 65536, 0, NULL, NULL) = 8192recvfrom(4, 0x7fffd9e48c90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=4, u64=38654705668}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=237, tv_nsec=465855000}) = 0time(NULL)                              = 1559698604 (2019-06-05T09:36:44+0800)epoll_wait(3, [{EPOLLIN, {u32=4, u64=38654705668}}], 4096, -1) = 1epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL)    = 0recvfrom(4, "\3442@o\362\340\10\240#\337=J2=\274\337\201\307=3O\324\342\35s7\\\16\7^\"\23"..., 65536, 0, NULL, NULL) = 19559brk(0x7fffd9f99000)                     = 0x7fffd9f99000close(4)                                = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc028910000, 2101248)         = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=237, tv_nsec=479677000}) = 0time(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) = 4epoll_ctl(3, EPOLL_CTL_DEL, 9, NULL)    = 0recvfrom(9, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 4096recvfrom(9, 0x7fffd9e68cb0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 9, {EPOLLIN, {u32=9, u64=38654705673}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 7, NULL)    = 0recvfrom(7, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 4096recvfrom(7, "V{\362b4\236\22\331\350H\357\313\374\314s\372N\3257\324\16\n\257\24H\217y\376\204P\3\206"..., 65536, 0, NULL, NULL) = 4096recvfrom(7, 0x7fffd9ea8cf0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLIN, {u32=7, u64=38654705671}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 17, NULL)   = 0recvfrom(17, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 8192recvfrom(17, 0x7fffd9ec8d10, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 17, {EPOLLIN, {u32=17, u64=38654705681}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 11, NULL)   = 0recvfrom(11, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 8192recvfrom(11, 0x7fffd9ee8d30, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 11, {EPOLLIN, {u32=11, u64=38654705675}}) = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=238, tv_nsec=747275000}) = 0time(NULL)                              = 1559698606 (2019-06-05T09:36:46+0800)madvise(0x7fffd9dcd000, 61440, MADV_DONTNEED) = 0madvise(0x7fffd9e39000, 126976, MADV_DONTNEED) = 0epoll_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) = 8epoll_ctl(3, EPOLL_CTL_DEL, 8, NULL)    = 0recvfrom(8, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 20480recvfrom(8, 0x7fffd9e28c70, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 8, {EPOLLIN, {u32=8, u64=38654705672}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 10, NULL)   = 0recvfrom(10, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 12288recvfrom(10, 0x7fffd9e88cd0, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 10, {EPOLLIN, {u32=10, u64=38654705674}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 12, NULL)   = 0recvfrom(12, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 20480recvfrom(12, 0x7fffd9f08d50, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 12, {EPOLLIN, {u32=12, u64=38654705676}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 19, NULL)   = 0recvfrom(19, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 20480recvfrom(19, 0x7fffd9f28d70, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 19, {EPOLLIN, {u32=19, u64=38654705683}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 18, NULL)   = 0recvfrom(18, "HTTP/1.1 200 OK\r\nContent-Type: t"..., 65536, 0, NULL, NULL) = 20480recvfrom(18, 0x7fffd9f48d90, 65536, 0, NULL, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_ADD, 18, {EPOLLIN, {u32=18, u64=38654705682}}) = 0epoll_ctl(3, EPOLL_CTL_DEL, 9, NULL)    = 0recvfrom(9, "V{\362b4\236\22\331\350H\357\313\374\314s\372N\3257\324\16\n\257\24H\217y\376\204P\3\206"..., 65536, 0, NULL, NULL) = 29504recvfrom(9, "\23\1_\243'\240C\301\37649\31\314\255\236\344f\22\305_\357hojll0FS\240\t\254"..., 65536, 0, NULL, NULL) = 6439close(9)                                = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc0221a0000, 2101248)         = 0epoll_ctl(3, EPOLL_CTL_DEL, 7, NULL)    = 0recvfrom(7, "3\231\3\372\375\"\271e\271cZ\343bb\251\331\314\227\323L\257\224\311\324\335\276(D\323\341\242\31"..., 65536, 0, NULL, NULL) = 31847close(7)                                = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc021f90000, 2101248)         = 0epoll_ctl(3, EPOLL_CTL_DEL, 17, NULL)   = 0recvfrom(17, "3\231\3\372\375\"\271e\271cZ\343bb\251\331\314\227\323L\257\224\311\324\335\276(D\323\341\242\31"..., 65536, 0, NULL, NULL) = 31847close(17)                               = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc021530000, 2101248)         = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=238, tv_nsec=783851000}) = 0time(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) = 6epoll_ctl(3, EPOLL_CTL_DEL, 11, NULL)   = 0recvfrom(11, "3\231\3\372\375\"\271e\271cZ\343bb\251\331\314\227\323L\257\224\311\324\335\276(D\323\341\242\31"..., 65536, 0, NULL, NULL) = 31847close(11)                               = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc021b60000, 2101248)         = 0epoll_ctl(3, EPOLL_CTL_DEL, 8, NULL)    = 0recvfrom(8, "\3442@o\362\340\10\240#\337=J2=\274\337\201\307=3O\324\342\35s7\\\16\7^\"\23"..., 65536, 0, NULL, NULL) = 19559close(8)                                = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc0225c0000, 2101248)         = 0epoll_ctl(3, EPOLL_CTL_DEL, 10, NULL)   = 0recvfrom(10, "\374\346{V\311\306\246|0F\276\337\0\370`\22\224\7\253\312\306\200\262~\374\250\20'\317\233w\r"..., 65536, 0, NULL, NULL) = 27751close(10)                               = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc0223b0000, 2101248)         = 0epoll_ctl(3, EPOLL_CTL_DEL, 12, NULL)   = 0recvfrom(12, "\3442@o\362\340\10\240#\337=J2=\274\337\201\307=3O\324\342\35s7\\\16\7^\"\23"..., 65536, 0, NULL, NULL) = 19559close(12)                               = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc021950000, 2101248)         = 0epoll_ctl(3, EPOLL_CTL_DEL, 19, NULL)   = 0recvfrom(19, "\3442@o\362\340\10\240#\337=J2=\274\337\201\307=3O\324\342\35s7\\\16\7^\"\23"..., 65536, 0, NULL, NULL) = 19559close(19)                               = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc021110000, 2101248)         = 0epoll_ctl(3, EPOLL_CTL_DEL, 18, NULL)   = 0recvfrom(18, "\3442@o\362\340\10\240#\337=J2=\274\337\201\307=3O\324\342\35s7\\\16\7^\"\23"..., 65536, 0, NULL, NULL) = 19559close(18)                               = 0write(1, "177115 bytes\n", 13)          = 13munmap(0x7fc021320000, 2101248)         = 0clock_gettime(CLOCK_MONOTONIC, {tv_sec=238, tv_nsec=802835000}) = 0time(NULL)                              = 1559698606 (2019-06-05T09:36:46+0800)futex(0x7fffd9e01ce0, FUTEX_WAKE_PRIVATE, 2147483647) = 4futex(0x7fffd9e01c90, FUTEX_WAKE_PRIVATE, 1) = 1futex(0x7fc023ff09d0, FUTEX_WAIT, 56, NULL) = -1 EAGAIN (Resource temporarily unavailable)epoll_ctl(3, EPOLL_CTL_DEL, 5, NULL)    = 0close(5)                                = 0close(6)                                = 0close(2)                                = 0close(1)                                = 0close(0)                                = 0munmap(0x7fc028fa0000, 2231560)         = 0munmap(0x7fc028d1f000, 2624568)         = 0close(3)                                = 0


本文原载于SegmentFault专栏“Swoole”,大量高赞内容详见“阅读原文”。

SegmentFault欢迎更多企业和开源项目来社区开设技术专栏,分享技术、塑造技术品牌,我们将给予持续的流量支持。



欢迎关注 SegmentFault 微信公众号 :)

图片

33820Swoole 4.4:支持 CURL 协程化

这个人很懒,什么都没留下

文章评论