Last active
July 7, 2017 07:11
-
-
Save huyi1985/fd3021b5d09cf87d6158dc83c4f9d91e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$connectTimeout = 0.003; | |
$timeout = 0.005; | |
$ip = ''; | |
$port = 0; | |
$key = 'foo'; | |
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array("sec"=>0, "usec"=> $connectTimeout * 1000000)); | |
$r = socket_connect($socket, $ip, $port); | |
echo socket_strerror(socket_last_error()), " ", socket_last_error(), PHP_EOL; | |
$command = "LRANGE $key 0 10\r\nQUIT\r\n"; | |
socket_send($socket, $command, strlen($command), MSG_EOF); | |
echo socket_strerror(socket_last_error()), " ", socket_last_error(), PHP_EOL; | |
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>0, "usec"=> $timeout * 1000000)); | |
$output = ""; | |
while($b = socket_recv($socket, $buf, 1024, MSG_WAITALL)) { | |
$output .= $buf; | |
} | |
echo socket_strerror(socket_last_error()), " ", socket_last_error(), PHP_EOL; | |
echo $buf, " ", $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment