Answer the question
In order to leave comments, you need to log in
PHP Socket Proxy Server?
Good afternoon, colleagues,
for the purpose of self-development, I am trying to deal with sockets
. In general, I open a socket, connect it to the server, send the following headers there
GET <a href="http://www.google.com/">www.google.com/</a> HTTP/1.1<br/>
Host: <a href="http://www.google.com">www.google.com</a><br/>
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1<br/>
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8<br/>
Accept-Language: en-us,en;q=0.5<br/>
Accept-Encoding: gzip, deflate<br/>
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7<br/>
Proxy-Connection: keep-alive<br/>
Cache-Control: max-age=0<br/>
HTTP/1.1 200 OK<br/>
Date: Tue, 18 Oct 2011 02:01:58 GMT<br/>
Expires: -1<br/>
Cache-Control: private, max-age=0<br/>
Content-Type: text/html; charset=UTF-8<br/>
Content-Encoding: gzip<br/>
Server: gws<br/>
Content-Length: 15101<br/>
X-XSS-Protection: 1; mode=block<br/>
X-Frame-Options: SAMEORIGIN<br/>
socket_write($this->_socket, $data, strlen($data));<br/>
return socket_read($this->_socket, 1024 * 1024);<br/>
Answer the question
In order to leave comments, you need to log in
Try retrying socket_read() until the socket is closed.
that is, do not immediately do RETURN, but first concatenate the fragments.
It's just that servers sometimes make delays between generating the header and sending the result. Just don't rush!
All in a bunch, maybe the conclusion itself is somehow not doing it right?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question