php socket手冊 http://php.net/manual/en/book.sockets.php本次socket使用筆記
set_time_limit (0);
$address = ‘localhost’;
$port = 4000;
// Create the socket
if(($sockd = socket_create(AF_INET, SOCK_STREAM,SOL_TCP))<1)
die("Unable to create socket:" . socket_strerror(socket_last_error()));
else
echo "Socket created ...\n";
if(socket_connect($sockd,$address,$port) == FALSE)
die("Unable to connect:" . socket_strerror(socket_last_error()));
else
echo "Socket connected ...\n";
$buffer = "null";
//if(socket_send($sockd, $buffer,1024,MSG_WAITALL) == false))
//if (false != ($bytes = socket_send($sockd, $buffer, 1024, MSG_WAITALL)))
//if(($bytes=socket_send($sockd,serialize($obj1),60, MSG_WAITALL))==false)
$send = "ok\0";
if(($bytes=socket_send($sockd,$send,strlen($send), MSG_WAITALL))==false)
{
die("Unable to connect:" . socket_strerror(socket_last_error()));
}
else
{ if($send == "ok\0")
{
socket_recv($sockd,$buffer,32,0);
socket_close($sockd);
}
else
{
socket_recv($sockd,$buffer,32,0);
socket_close($sockd);
}
}
echo "RETURN = $buffer \n";
?>