To solve this problem, php often fails to respond to requests from other servers. 1. use file_get_contents directly to implement file_get_contents ($ url); 2. use curl extension. & nbsp; $ chcurl_init (); & nbsp; $ timeout30; & nbsp; curl_setopt ($ ch, CURLO for obfuscation, php often fails to respond to requests from other servers.
1. use file_get_contents directly.
File_get_contents ($ url );
2. use curl extension.
$ Ch = curl_init ();
$ Timeout = 30;
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout );
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
$ Contents = trim (curl_exec ($ ch ));
Curl_close ($ ch );
3 socket.
$ Address = 'http: // 1.2.3.4: 9001 /';
$ Path = '/aaa/bbb ';
$ Sock = fsockopen ($ address, 80, $ errno, $ errstr, 30 );
If (! $ Sock) die ("$ errstr ($ errno) \ n ");
$ Psw = md5 ('192. 100 ');
$ Data = "xxx = xxx & yyy = yyy ";
Fwrite ($ sock, "POST $ path HTTP/1.0 \ r \ n ");
Fwrite ($ sock, "Host: localhost \ r \ n ");
Fwrite ($ sock, "Content-type: application/x-www-form-urlencoded \ r \ n ");
Fwrite ($ sock, "Content-length:". strlen ($ data). "\ r \ n ");
Fwrite ($ sock, "Accept: */* \ r \ n ");
Fwrite ($ sock, "\ r \ n ");
Fwrite ($ sock, "$ data \ r \ n ");
Fwrite ($ sock, "\ r \ n ");
$ Headers = "";
While ($ str = trim (fgets ($ sock, 4096 )))
$ Headers. = "$ str \ n ";
$ Body = "";
While (! Feof ($ sock ))
$ Body. = fgets ($ sock, 4096 );
Fclose ($ sock );
$ Body1 = explode ("#", $ body );
Return $ body1;
All three methods are slow.
Echo ""; output is normal.
The above code is actually run in the for loop. The effect of packet capture below
Previously, the access was quite good. recently, it often gets stuck during use. An error is reported.
Please help me!
------ Solution --------------------
1. check whether the cookie is affected.
2. set the route
They are all intranet addresses. what are they doing if they are so messy?
------ Solution --------------------
Is the source address network poor?
------ Solution --------------------
Discussion
It is obviously requested, and the connection resources are limited. Is there a way to establish a persistent connection. Use this resource when necessary. You do not need to open a resource every time you connect.
------ Solution --------------------
Discussion
It is obviously requested, and the connection resources are limited. Is there a way to establish a persistent connection. Use this resource when necessary. You do not need to open a resource every time you connect.
------ Solution --------------------
The connection is too frequent. suspected DOS attacks are blacklisted.
Directly use curl to request keepalive.
CURLOPT_FRESH_CONNECT => false
CURLOPT_FORBID_REUSE => false
Configure these two options. you do not need to disable curl_exec and continue to use it next time.