本文介绍了为什么php5-fpm post请求是慢的,而php-cli代码/控制台curl工作非常快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我使用虚拟方法对本地api网络服务(通过LAN)执行POST请求,本身工作速度非常快(少于一秒)。 问题是如果我使用php5-fpm它需要很长时间来执行POST请求( curl post ,流)。 如果我使用php-cli脚本与相同的代码或控制台curl命令 - 它的工作速度非常快,像一个魅力。 em>奇怪的事情:如果我使用 system 从php5-fpm执行控制台curl命令,它花了很多时间来执行请求。所以,没有办法欺骗:( 我使用直接ipv4地址消除DNS问题(我试图定义 CURLOPT_IPRESOLVE CURLOPT_POSTFIELDS 选项,请求的速度非常快 我使用的是debian jessie官方的php 5.6.9包。 所以,为什么这个问题发生在php5-fpm? 我的curl php代码: $ data = json_encode(['id'=> 1,'method'=>'test','sid' => session_id(),]); $ curl = curl_init(); curl_setopt($ curl,CURLOPT_URL,'http://192.168.182.22') ; curl_setopt($ curl,CURLOPT_HTTPHEADER,[')Content-type:$ curl_setopt($ curl,CURLOPT_RETURNTRANSFER,true); curl_setopt($ curl,CURLOPT_POST, application / json','Content-length:'。strlen($ data)]); curl_setopt($ curl,CURLOPT_POSTFIELDS,$ data); $ out = curl_exec($ curl); curl_close($ curl); Curl获取信息输出(显示 starttransfer_time 很慢): array(26){ [url] => string(22)http://192.168.182.22/ [content_type] => string(24)text / html; charset = UTF-8 [http_code] => int(200) [header_size] => int(532) [request_size] => int(188) [filetime] => int(-1) [ssl_verify_result] => int(0) [redirect_count] => int(0) [total_time] => float(10.285093) [namelookup_time] => float(3.2E-5) [connect_time] => float(0.000156) [pretransfer_time] => float(0.000181) [size_upload] => float(82) [size_download] => float(99) [speed_download] => float(9) [speed_upload] => float(7) [download_content_length] => float(-1) [upload_content_length] => float(82) [starttransfer_time] => float(10.285052) [redirect_time] => float(0) [redirect_url] => string(0) [primary_ip] => string(14)192.168.182.22 [certinfo] => array(0){} [primary_port] => int(80) [local_ip] => string(14)192.168.182.20 [local_port] => int(49286)} 它也工作缓慢(有点快,然后curl,但无论如何,我可以得到40-50秒的延迟): $ url = 'http://192.168.182.22/'; $ data = json_encode(['id'=> 1,'method'=>'test','sid'=> session_id ]); $ headers = ['Content-type:application / json','Connection:close','Content-Length:'。 strlen($ data)]; $ options = array('http'=> array('header'=> join(\r\\\,$ headers)。 \r\\\,'method'=>'POST','content'=> $ data,),); $ context = stream_context_create($ options); $ result = file_get_contents($ url,false,$ context); diff / etc / php5 / fpm / php .ini /etc/php5/cli/php.ini : 303c303 < ; disable_functions选项= pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, $ --- b $ b> disable_functions = 363c363 < expose_php = Off --- > expose_php = On 393c393 < memory_limit = 256M --- > memory_limit = -1 660c660 < post_max_size = 200M --- > post_max_size = 8M 810c810 < upload_max_filesize = 200M --- > upload_max_filesize = 2M tcpdump中的主要内容可以看到不同 - php5-fpm请求包括ARP请求。我不能看到这样在控制台curl / php-cli。当远程api服务器想要返回响应,但是找不到如何执行这个操作的方法时,可能会出现问题。 (@ Mircea建议添加静态arp路由,添加它们,ARP请求从tcpdump消失,但暂停仍然存在)。 php5-fpm的tcpdump输出: 00:55:22.347822 IP 192.168.182.20.52659> 192.168.182.22.80:Flags [S],seq 4210728690,win 29200,options [mss 1460,sackOK,TS val 301284147 ecr 0,nop,wscale 7],length 0 E ..& 。@ ..〜........... P .......... r ............ ..; 3 .. ...... 00:55:22.347898 IP 192.168.182.22.80> 192.168.182.20.52659:标志[S.],seq 2702388053,ack 4210728691,win 28960,options [mss 1460,sackOK,TS val 280740546 ecr 301284147,nop,wscale 7],length 0 E .. ; .. @。@。M @ ......... P .... + U ... q .R ......... ... ...; 3 .... 00:55:22.347906 IP 192.168.182.20.52659> 192.168.182.22.80:Flags [。],ack 1,win 229,options [nop,nop,TS val 301284147 ecr 280740546],length 0 E..4 .. @。@ ..... ......... P ... + V ........... ..; 3 .... 00:55:22.347942 IP 192.168.182.20.52659> 192.168.182.22.80:Flags [P.],seq 1:206,ack 1,win 229,options [nop,nop,TS val 301284147 ecr 280740546],length 205 E ..... @ @ .............. P ...... + V ..... o ..... ..; 3 .... POST / HTTP /1.1 Host:192.168.182.22 Content-Type:application / x-www-form-urlencoded Content-Length:82 Accept:* / * {id:1,method:station.sync,params:[1],sid:1gn8f4mhctui9ki91bla6osnf4} 00:55:22.347997 IP 192.168.182.22.80> 192.168.182.20.52659:标志[。],ack 206,win 235,options [nop,nop,TS val 280740547 ecr 301284147],length 0 E..4 .. @。@。c。 ....... P .... + V ........ 2 ...... ......; 3 00:55:27.356575 ARP,Request who-has 192.168.182.22 tell 192.168.182.20,length 28 ..........)。4 ............... 00:55:27.356777 ARP,回复192.168.182.22是在00:0c:29:46:99:bc,长度46 ..........)F .... ....)4 ....................... 00:55:36.742347 IP 192.168.182.22.80> 192.168.182.20.52659:Flags [P.],seq 1:558,ack 206,win 235,options [nop,nop,TS val 280744145 ecr 301284147],length 557 E..a .. @ @ .a .......... P .... + V ........ a ...... ......; 3HTTP / 1.1 200 OK 服务器:nginx / 1.6.2 日期:Wed,01 Jul 2015 21:55:36 GMT Content-Type:application / json Transfer-Encoding:chunked 连接:keep-alive 过期时间:Thu,19 Nov 1981 08:52:00 GMT 高速缓存控制:no-store,no-cache,必须重新验证,post-check = 0 ,pre-check = 0 Pragma:no-cache Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:Content-Type,X-Requested- With 访问控制允许方法:GET,POST,OPTIONS p3p:CP = IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS我们的IND CNT 16 {id:1,result:true} 0 00:55:36.742374 IP 192.168.182.20.52659& 192.168.182.22.80:Flags [。],ack 558,win 237,options [nop,nop,TS val 301287746 ecr 280744145],length 0 E..4 .. @。@ ..... ......... P ......-............ ..IB .... 00:55:36.742486 IP 192.168.182.20.52659> 192.168.182.22.80:Flags [F.],seq 206,ack 558,win 237,options [nop,nop,TS val 301287746 ecr 280744145],length 0 E..4 .. @。@。 ............. P ......- ............ ..IB .... 00: 55:36.742559 IP 192.168.182.22.80> 192.168.182.20.52659:flags [F.],seq 558,ack 207,win 235,options [nop,nop,TS val 280744145 ecr 301287746],length 0 E..4 .. @。@。 c .......... P ....- ..........:..... ...... IB 00: 55:36.742566 IP 192.168.182.20.52659> 192.168.182.22.80:Flags [。],ack 559,win 237,options [nop,nop,TS val 301287746 ecr 280744145],length 0 E..4 .. @。@ ..... ......... P ......-............ ..IB .... 00:55:41.744102 ARP ,请求who-has 192.168.182.20 tell 192.168.182.22,长度46 ..........)F ................... ............... 00:55:41.744121 ARP,回复192.168.182.20是在00:0c:29:04:34:c9,长度28 ..........)。4 .......)F ...... tcpdump输出用于快速(console / php-cli)请求: 0:43:46.854062 IP 192.168.182.20.52527> 192.168.182.22.80:Flags [S],seq 560731240,win 29200,options [mss 1460,sackOK,TS val 301110274 ecr 0,nop,wscale 7],length 0 E .. ......... ... 00:43:46.854198 IP 192.168.182.22.80> 192.168.182.20.52527:Flags [S],seq 1849811122,ack 560731241,win 28960,options [mss 1460,sackOK,TS val 280566673 ecr 301110274,nop,wscale 7],length 0 E .. ; .. @。@。M @ ......... P./nA..!li.q ........... ....... ..... 00:43:46.854216 IP 192.168.182.20.52527> 192.168.182.22.80:Flags [。],ack 1,win 229,options [nop,nop,TS val 301110274 ecr 280566673],length 0 E..4.k @。@ ..... ....... /。P!l.inA ............. ........ 00:43:46.854265 IP 192.168 .182.20.52527> 192.168.182.22.80:标志[P.],seq 1:233,ack 1,win 229,选项[nop,nop,TS val 301110274 ecr 280566673],长度232 E .... @ ............ /。P!l.inA ............. ........ POST / HTTP / 1.1 User-Agent:curl / 7.38.0 主机:192.168.182.22 接受:* / * Content-Length:84 Content-Type:application / x-www-form-urlencoded {id:1,sid:1gn8f4mhctui9ki91bla6osnf4,method:station.sync,params:[10] $ b 00:43:46.854317 IP 192.168.182.22.80> 192.168.182.20.52527:标志[。],ack 233,win 235,options [nop,nop,TS val 280566673 ecr 301110274],length 0 E..4@。@。R%.. ....... P./nA ..!lQ ... b ...... ........ 00:43:46.891248 IP 192.168.182.22 .80> 192.168.182.20.52527:标志[P.],seq 1:615,ack 233,win 235,options [nop,nop,TS val 280566682 ecr 301110274],长度614 E 。#@。@。O .......... P./nA ..!IQ .......... ........ HTTP / 1.1 200 OK 服务器:nginx / 1.6.2 日期:Wed,01 Jul 2015 21:43:46 GMT Content-Type:application / json Transfer-Encoding:chunked 连接:keep-alive 到期日:Thu,19 Nov 1981 08:52:00 GMT 高速缓存控制:无存储,无高速缓存,必须重新生效,后检查= 0,pre-check = 0 Pragma:no-cache 访问控制允许证书:真访问控制允许头:内容类型,X请求访问控制允许方法:GET,POST,OPTIONS p3p:CP = IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS我们的IND CNT 4f {id:1,error:{code:SERVER_ERROR,message:站#10未运行}} 0 00:43:46.891273 IP 192.168.182.20.52527> 192.168.182.22.80:Flags [。],ack 615,win 238,options [nop,nop,TS val 301110283 ecr 280566682],length 0 E..4.m @。@ ..... ....... /。P!l.QnA ............. ........ 00:43:46.891932 IP 192.168 .182.20.52527> 192.168.182.22.80:Flags [F.],seq 233,ack 615,win 238,options [nop,nop,TS val 301110283 ecr 280566682],length 0 E..4.n @。@ ........... /。P!l.QnA ............. ........ 00:43 :46.896944 IP 192.168.182.22.80> 192.168.182.20.52527:Flags [F.],seq 615,ack 234,win 235,options [nop,nop,TS val 280566684 ecr 301110283],length 0 E..4。$ @。@。 R#......... P./nA ..!lR ...`i ..... ........ 00:43:46.896954 IP 192.168.182.20.52527> 192.168.182.22.80:Flags [。],ack 616,win 238,options [nop,nop,TS val 301110285 ecr 280566684],length 0 E..4.o @。@ ..... ....... /。P!l.RnA ............. ........ 解决方案我只是追踪了一个类似的问题。我认为这可能是同一个原因。我遇到类似avasin的问题。我发现php-fpm curl到localhost是慢的,但是php-cli curl到localhost是非常快。此外,调试curl时序在php-fpm中显示高的 starttransfer_time ,但在php过程中显得很低。 根本原因昨天,问题是php-fpm www.conf 配置。 Becuase php-fpm具有低 start_server ,php-fpm实际上必须用有限数量的php-fpm进程处理curl。解决方案是增加 start_server 的数量,这将影响您的php-fpm可以处理的并发数。 当并发性超过当前php-fpm进程的数量时,性能将大幅下降。因此,使一切都感觉很慢。 php-cli没有相同的问题,因为它可以启动许多php进程,只要你有足够的内存,所以它总是快。我在这里做了很多实验 php curl localhost在做并发请求。看看你是否有兴趣。 I am performing POST request to local api web service (via LAN) with dummy method, that works very fast itself (less then a second).Problem is that if i use php5-fpm it takes extremely long time to perform POST request (curl post, streams).If i use php-cli script with same code or console curl command - it works very fast, like a charm.Strange thing: if i use system to execute console curl command from php5-fpm it tooks a lot of time to perform the request. So, no way to cheat :(I am using direct ipv4 address to eliminate DNS problems (i tried to define CURLOPT_IPRESOLVE option, but perfomance was same).If i omit curl CURLOPT_POSTFIELDS option, request is very fast in php5-fpm too. I am using debian jessie with official php 5.6.9 package.So, why this problem is happening with php5-fpm?My curl php code:$data = json_encode([ 'id' => 1, 'method' => 'test', 'sid' => session_id(),]);$curl = curl_init();curl_setopt($curl, CURLOPT_URL, 'http://192.168.182.22');curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);curl_setopt($curl, CURLOPT_POST, true);curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Content-type: application/json', 'Content-length: ' . strlen($data)]);curl_setopt($curl, CURLOPT_POSTFIELDS, $data);$out = curl_exec($curl);curl_close($curl);Curl get info output (shows that starttransfer_time is very slow):array(26) { ["url"]=> string(22) "http://192.168.182.22/" ["content_type"]=> string(24) "text/html; charset=UTF-8" ["http_code"]=> int(200) ["header_size"]=> int(532) ["request_size"]=> int(188) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(10.285093) ["namelookup_time"]=> float(3.2E-5) ["connect_time"]=> float(0.000156) ["pretransfer_time"]=> float(0.000181) ["size_upload"]=> float(82) ["size_download"]=> float(99) ["speed_download"]=> float(9) ["speed_upload"]=> float(7) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(82) ["starttransfer_time"]=> float(10.285052) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(14) "192.168.182.22" ["certinfo"]=> array(0) { } ["primary_port"]=> int(80) ["local_ip"]=> string(14) "192.168.182.20" ["local_port"]=> int(49286)}Another try with streams. It also works slow (a bit faster then curl, but anyway i can get 40-50 seconds delay):$url = 'http://192.168.182.22/';$data = json_encode([ 'id' => 1, 'method' => 'test', 'sid' => session_id(),]);$headers = [ 'Content-type: application/json', 'Connection: close', 'Content-Length: ' . strlen($data)];$options = array( 'http' => array( 'header' => join("\r\n", $headers) . "\r\n", 'method' => 'POST', 'content' => $data, ),);$context = stream_context_create($options);$result = file_get_contents($url, false, $context);There is no significant difference in diff /etc/php5/fpm/php.ini /etc/php5/cli/php.ini:303c303< disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,---> disable_functions =363c363< expose_php = Off---> expose_php = On393c393< memory_limit = 256M---> memory_limit = -1660c660< post_max_size = 200M---> post_max_size = 8M810c810< upload_max_filesize = 200M---> upload_max_filesize = 2MMain thing in tcpdump i can see differ - php5-fpm requests includes ARP requests. I can't see such in console curl/php-cli. Perhaps problem happens when remote api server wants to return response, but can't find a way how to perform this?(@Mircea adviced to add static arp routes, we added them, ARP requests disappeared from tcpdump, but pauses are still present).tcpdump output for php5-fpm: 00:55:22.347822 IP 192.168.182.20.52659 > 192.168.182.22.80: Flags [S], seq 4210728690, win 29200, options [mss 1460,sackOK,TS val 301284147 ecr 0,nop,wscale 7], length 0E..<..@.@..~...........P..........r..............;3........00:55:22.347898 IP 192.168.182.22.80 > 192.168.182.20.52659: Flags [S.], seq 2702388053, ack 4210728691, win 28960, options [mss 1460,sackOK,TS val 280740546 ecr 301284147,nop,wscale 7], length 0E..<..@[email protected]@.........P....+U......q .R...............;3....00:55:22.347906 IP 192.168.182.20.52659 > 192.168.182.22.80: Flags [.], ack 1, win 229, options [nop,nop,TS val 301284147 ecr 280740546], length 0E..4..@[email protected]......+V.............;3....00:55:22.347942 IP 192.168.182.20.52659 > 192.168.182.22.80: Flags [P.], seq 1:206, ack 1, win 229, options [nop,nop,TS val 301284147 ecr 280740546], length 205E.....@[email protected]......+V.....o.......;3....POST / HTTP/1.1Host: 192.168.182.22Content-Type: application/x-www-form-urlencodedContent-Length: 82Accept: */*{"id":1,"method":"station.sync","params":[1],"sid":"1gn8f4mhctui9ki91bla6osnf4"}00:55:22.347997 IP 192.168.182.22.80 > 192.168.182.20.52659: Flags [.], ack 206, win 235, options [nop,nop,TS val 280740547 ecr 301284147], length 0E..4..@[email protected]....+V........2............;300:55:27.356575 ARP, Request who-has 192.168.182.22 tell 192.168.182.20, length 28..........).4...............00:55:27.356777 ARP, Reply 192.168.182.22 is-at 00:0c:29:46:99:bc, length 46..........)F........).4.......................00:55:36.742347 IP 192.168.182.22.80 > 192.168.182.20.52659: Flags [P.], seq 1:558, ack 206, win 235, options [nop,nop,TS val 280744145 ecr 301284147], length 557E..a..@[email protected]....+V........a............;3HTTP/1.1 200 OKServer: nginx/1.6.2Date: Wed, 01 Jul 2015 21:55:36 GMTContent-Type: application/jsonTransfer-Encoding: chunkedConnection: keep-aliveExpires: Thu, 19 Nov 1981 08:52:00 GMTCache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0Pragma: no-cacheAccess-Control-Allow-Credentials: trueAccess-Control-Allow-Headers: Content-Type, X-Requested-WithAccess-Control-Allow-Methods: GET, POST, OPTIONSp3p: CP=IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT16{"id":1,"result":true}000:55:36.742374 IP 192.168.182.20.52659 > 192.168.182.22.80: Flags [.], ack 558, win 237, options [nop,nop,TS val 301287746 ecr 280744145], length 0E..4..@[email protected]:55:36.742486 IP 192.168.182.20.52659 > 192.168.182.22.80: Flags [F.], seq 206, ack 558, win 237, options [nop,nop,TS val 301287746 ecr 280744145], length 0E..4..@[email protected]:55:36.742559 IP 192.168.182.22.80 > 192.168.182.20.52659: Flags [F.], seq 558, ack 207, win 235, options [nop,nop,TS val 280744145 ecr 301287746], length 0E..4..@[email protected]..........:...........IB00:55:36.742566 IP 192.168.182.20.52659 > 192.168.182.22.80: Flags [.], ack 559, win 237, options [nop,nop,TS val 301287746 ecr 280744145], length 0E..4..@[email protected]:55:41.744102 ARP, Request who-has 192.168.182.20 tell 192.168.182.22, length 46..........)F..................................00:55:41.744121 ARP, Reply 192.168.182.20 is-at 00:0c:29:04:34:c9, length 28..........).4.......)F......tcpdump output for fast (console/php-cli) requests:0:43:46.854062 IP 192.168.182.20.52527 > 192.168.182.22.80: Flags [S], seq 560731240, win 29200, options [mss 1460,sackOK,TS val 301110274 ecr 0,nop,wscale 7], length 0E..<.j@.@............/.P!l.h......r........................00:43:46.854198 IP 192.168.182.22.80 > 192.168.182.20.52527: Flags [S.], seq 1849811122, ack 560731241, win 28960, options [mss 1460,sackOK,TS val 280566673 ecr 301110274,nop,wscale 7], length 0E..<..@[email protected]@.........P./nA..!l.i..q .......................00:43:46.854216 IP 192.168.182.20.52527 > 192.168.182.22.80: Flags [.], ack 1, win 229, options [nop,nop,TS val 301110274 ecr 280566673], length 0E..4.k@.@............/.P!l.inA.....................00:43:46.854265 IP 192.168.182.20.52527 > 192.168.182.22.80: Flags [P.], seq 1:233, ack 1, win 229, options [nop,nop,TS val 301110274 ecr 280566673], length 232E....l@.@............/.P!l.inA.....................POST / HTTP/1.1User-Agent: curl/7.38.0Host: 192.168.182.22Accept: */*Content-Length: 84Content-Type: application/x-www-form-urlencoded{"id":1, "sid": "1gn8f4mhctui9ki91bla6osnf4","method":"station.sync", "params":[10]}00:43:46.854317 IP 192.168.182.22.80 > 192.168.182.20.52527: Flags [.], ack 233, win 235, options [nop,nop,TS val 280566673 ecr 301110274], length 0E..4."@[email protected]%.........P./nA..!l.Q....b..............00:43:46.891248 IP 192.168.182.22.80 > 192.168.182.20.52527: Flags [P.], seq 1:615, ack 233, win 235, options [nop,nop,TS val 280566682 ecr 301110274], length 614E....#@[email protected]./nA..!l.Q...................HTTP/1.1 200 OKServer: nginx/1.6.2Date: Wed, 01 Jul 2015 21:43:46 GMTContent-Type: application/jsonTransfer-Encoding: chunkedConnection: keep-aliveExpires: Thu, 19 Nov 1981 08:52:00 GMTCache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0Pragma: no-cacheAccess-Control-Allow-Credentials: trueAccess-Control-Allow-Headers: Content-Type, X-Requested-WithAccess-Control-Allow-Methods: GET, POST, OPTIONSp3p: CP=IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT4f{"id":1,"error":{"code":"SERVER_ERROR","message":"Station #10 is not running"}}000:43:46.891273 IP 192.168.182.20.52527 > 192.168.182.22.80: Flags [.], ack 615, win 238, options [nop,nop,TS val 301110283 ecr 280566682], length 0E..4.m@.@............/.P!l.QnA.....................00:43:46.891932 IP 192.168.182.20.52527 > 192.168.182.22.80: Flags [F.], seq 233, ack 615, win 238, options [nop,nop,TS val 301110283 ecr 280566682], length 0E..4.n@.@............/.P!l.QnA.....................00:43:46.896944 IP 192.168.182.22.80 > 192.168.182.20.52527: Flags [F.], seq 615, ack 234, win 235, options [nop,nop,TS val 280566684 ecr 301110283], length 0E..4.$@[email protected]#.........P./nA..!l.R....`i.............00:43:46.896954 IP 192.168.182.20.52527 > 192.168.182.22.80: Flags [.], ack 616, win 238, options [nop,nop,TS val 301110285 ecr 280566684], length 0E..4.o@.@............/.P!l.RnA..................... 解决方案 I just track down a similar issue of my own. I think it might be the same reason. I encounter the similar issue like avasin. I found that php-fpm curl to localhost is slow, but php-cli curl to localhost is extremely fast. Plus, debugging curl timing shows high starttransfer_time in php-fpm but rather low in php process.I found the root cause yesterday, the issue is the php-fpm www.conf config. Becuase php-fpm has low start_server, php-fpm actually has to process curl with limited number of php-fpm processes. The solution is to increase the number of start_server, this will affect the number of concurrency which your php-fpm could handle. The performance will decrease drastically when the concurrency exceeds the number of current php-fpm processes. Hence, making everything feels slow. The php-cli does not have the same issue since it could launch many php processes as long as you have enough memory, so it is always fast. I did a lot of experiments here php curl localhost is slow when making concurrent requests. Take a look if you're interested. 这篇关于为什么php5-fpm post请求是慢的,而php-cli代码/控制台curl工作非常快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 16:42