php server script: stream_select returning false

389
May 31, 2017, at 11:04 AM

I am new to socket programming. the following snippet of code just keeps the server waiting. But If I remove line 22 (delete server socket), the server responds with all the code before line 22, but gives the stream_select error message and stops. I have copied this code as is from other online sources. Can anybody pls help.

while (true) {
// prepare readable sockets
$read_sockets = $client_sockets;
$read_sockets[] = $server;
// start reading and use a large timeout
if(false === stream_select($read_sockets, $write, $except, 300000)) {
die('stream_select error.');
}
// new client
if(in_array($server, $read_sockets)) {
    $new_client = stream_socket_accept($server);
    if ($new_client) {
        //print remote client information, ip and port number
        echo 'new connection: ' . stream_socket_get_name($new_client, true) 
        . "\n";
        $client_sockets[] = $new_client;
        echo "total clients: ". count($client_sockets) . "\n";
        //$output = "hello new client.\n";
        //fwrite($new_client, $output);
    }
    //delete the server socket from the read sockets
    //unset($read_sockets[ array_search($server, $read_sockets) ]);
}
// message from existing client
foreach ($read_sockets as $socket) {
    $data = fread($socket, 128);
    echo "data: " . $data . "\n";
    $tk103_data = explode( ',', $data);
    $response = ""; 
------->
Rent Charter Buses Company
READ ALSO
How do I go about creating a 'Data Entry Form' to output HTML Code?

How do I go about creating a 'Data Entry Form' to output HTML Code?

I manage a very popular Business Conference Directory

247
Error JSONSerialization

Error JSONSerialization

I have the following code:

355
Why does this code output all the previous output rather than only the current iteration?

Why does this code output all the previous output rather than only the current iteration?

I have a Laravel api that I'm using to learn about buffers and I cannot seem to figure out why my outputs stack rather than give me only the current iterationAs an example the following code outputs the loop iteration count:

231
Yii2 - kartik-v: Editable Column jQuery(…).datetimepicker is not a function

Yii2 - kartik-v: Editable Column jQuery(…).datetimepicker is not a function

I am requesting data using pjax on click of checkboxAt first load it works fine but when pjax response inserts the data

417