To solve this problem, php often fails to respond to requests from other servers.
Source: Internet
Author: User
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; $ ch = curl_init (); & nbsp. php often fails to respond to requests from other servers.
1. use file_get_contents directly.
File_get_contents ($ url );
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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.