PHP
Chilkat2 PHP
Poll a Socket for Available Data
See more Socket/SSL/TLS Examples
Demonstrates Socket.PollDataAvailable, which performs a nonblocking check for readable activity and returns whether data or another read-ready condition is present.
Background. This lets an application check for incoming data without blocking, for example in an event loop that services multiple tasks.
Chilkat PHP Downloads
<?php
use Chilkat2\Socket;
$socket = new Socket();
// Connect to the server using TLS.
$bTls = true;
$maxWaitMs = 5000;
try {
$socket->Connect('example.com', 5000, $bTls, $maxWaitMs);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Perform a nonblocking check for readable data. Returns true when data or another read-ready
// condition is present, and false when nothing is immediately available.
$bAvailable = $socket->PollDataAvailable();
if (!$bAvailable) {
echo "No data is immediately available.\n";
} else {
echo "Data is available to read.\n";
}