I am trying to creating websocket with php and here is my connection that i used for create socket connection
<?php
if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
echo "Socket created \n";
//Connect socket to remote server
if(!socket_connect($sock , '173.194.40.18' , 80))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not connect: [$errorcode] $errormsg \n");
}
echo "Connection established \n";
$message = "GET / HTTP/1.1\r\n\r\n";
//Send the message to the server
if( ! socket_send ( $sock , $message , strlen($message) , 0))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not send data: [$errorcode] $errormsg \n");
}
echo "Message send successfully \n";
//Now receive reply from server
if(socket_recv ( $sock , $buf , 2045 , MSG_WAITALL ) === FALSE)
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not receive data: [$errorcode] $errormsg \n");
}
//print the received message
echo $buf;
socket_close($sock);
This code i tried in browser and got only this
Socket created Connection established Message send successfully
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\WebsocketTests\phpwebsocket.php on line 38
and in terminal i got this
Socket created
Connection established
Message send successfully
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.it/?gfe_rd=cr&ei=0011VfCvN8XD8geqj4D4BA
Content-Length: 258
Date: Mon, 08 Jun 2015 08:09:55 GMT
Server: GFE/2.0
Alternate-Protocol: 80:quic,p=0
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.it/?gfe_rd=cr&ei=0011VfCvN8XD8geqj4D4BA">here</A>
.
</BODY></HTML>
somebody can tell me why i am getting different result in browser and cmd shell ?