<?php
}
// $ip = gethostbyname('ya.ru');
$ip = '127.0.0.1' ;
$port = 8123 ;
$useNoBlock = in_array ( '--no-block' , $argv ) ; $isFailtTest = in_array ( '--fail' , $argv ) ;
if ( $isFailtTest ) {
$port = 80 ;
echo "Please disconnect LAN after connect\n " ;
}
echo "Connect to $ip :$port \n " ;
if ( $useNoBlock ) {
}
if ( ! canIgnoreError( $useNoBlock ) ) {
} else {
}
}
while ( true ) {
if ( $useNoBlock ) {
waitFor( $s ) ;
}
if ( $data === false ) {
if ( ! canIgnoreError( $useNoBlock ) ) {
} else {
continue ;
}
}
echo "> " . $data . "\n " ;
}
echo "EOF or error\n " ;
function waitFor( $s )
{
$read = [ $s ] ;
$write = [ $s ] ;
$except = [ $s ] ;
echo "Wait ...\n " ;
if ( $read ) {
echo "Read event\n " ;
}
if ( $write ) {
echo "Write event\n " ;
}
if ( $except ) {
echo "Except event\n " ;
}
}
/**
* Можно ли игнорировать ошибку вроде SOCKET_EWOULDBLOCK
*/
function canIgnoreError( $useNoBlock )
{
if ( ! $useNoBlock ) {
return ;
}
if ( defined ( 'SOCKET_EAGAIN' ) && $e == SOCKET_EAGAIN
) { return true ;
}
return in_array ( $e , [ SOCKET_EWOULDBLOCK
, SOCKET_EINPROGRESS
] ) ; }
PD9waHAKCmlmICggISRzID0gc29ja2V0X2NyZWF0ZShBRl9JTkVULCBTT0NLX1NUUkVBTSwgU09MX1RDUCkgKSB7CiAgICB0aHJvdyBuZXcgRXhjZXB0aW9uKCdzb2NrZXRfY3JlYXRlIGZhaWxlZDogJyAuIHNvY2tldF9zdHJlcnJvcihzb2NrZXRfbGFzdF9lcnJvcigpKSApOwp9CgovLyAkaXAgPSBnZXRob3N0YnluYW1lKCd5YS5ydScpOwokaXAgPSAnMTI3LjAuMC4xJzsKJHBvcnQgPSA4MTIzOwokdXNlTm9CbG9jayA9IGluX2FycmF5KCctLW5vLWJsb2NrJywgJGFyZ3YpOwokaXNGYWlsdFRlc3QgPSBpbl9hcnJheSg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