PHP Classes
elePHPant
Icontem

Stream PSR 7 Client and Server: PSR 7 based network connection client and server

Recommend this page to a friend!
  Info   View files Documentation   View files View files (54)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-11-01 (19 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 114 This week: 1All time: 8,721 This week: 627Up
Version License PHP version Categories
stream7 1.0.2MIT/X Consortium ...5Networking, PHP 5, Stream wrappers, PSR
Description Author

This package is PSR 7 based network connection client and server.

The server can listen to network connections and can read and write to the client.

The client can connect to a given server and send or receive data.

  Performance   Level  
Name: Payam Naderi <contact>
Classes: 9 packages by
Country: Iran Iran
Age: 34
All time rank: 272046 in Iran Iran
Week rank: 38 Up1 in Iran Iran Up
Innovation award
Innovation award
Nominee: 2x

Details

Poirot\Stream

[Documentation is out dated for now]

Connection Oriented Transports (such as TCP)

__Server__

ob_end_clean();
header("Connection: keep-alive");
ignore_user_abort(); // optional

ob_start();
echo ('Server Listening ....');
ob_end_flush(); // Strange behaviour, will not work
flush();

$connect = function()
{
    // Create TCP Server And Bind On Port #8000
    $socket = new StreamServer('tcp://0.0.0.0:8000');
    $socket->bind();

    return $socket;
};

/ @var StreamServer $socketServer */
$socketServer = $connect();
while (1)
{
    try {
        // Listen On Port Till Client Connect ...
        $streamable = $socketServer->listen();
    } catch (TimeoutException $e) {
        // If Connection Timeout Connect Again, and listen
        $socketServer->shutdown();     // free server port
        $socketServer = $connect();    // connect again ..
        continue;
    }

    ob_start();
    echo '<br/><br/>'."Client Connected: "
        .(
            $streamable->getResource()
                ->getRemoteName()
        );
    ob_end_flush();flush();

    // While Client Not Closed Connection ...
    $response = '';
    while ($streamable->getResource()->isAlive())
    {
        $clientMessage = $streamable->readLine();

        ob_start();
        switch ($clientMessage) {
            case 'bye':
                echo '<br/>'."> bye "
                    .(
                    $streamable->getResource()
                        ->getRemoteName()
                    );

                // send back response
                $streamable->write($response);

                // close client connection
                $streamable->getResource()->close();
                break;
            case 'time':
                echo '<br/> >'.$clientMessage;
                $response .= date("D M j H:i:s Y\r\n");
                break;
            default:
                echo '<br/>'.'>'.$clientMessage. ', Not Recognized.';
        }
        ob_end_flush();flush();
    }
}

__Client__

$socks  = new StreamClient('tcp://127.0.0.1:8000');

try {
    $resrc = $socks->getConnect();
} catch (\Exception $e) {
    throw new \Exception('Not Connected.', null, $e);
}

$clientStream = new Streamable($resrc);
echo $clientStream->getResource()->getLocalName();

$clientStream->sendData("time\n");
$clientStream->sendData("not known command\n");
$clientStream->sendData("bye\n");

// Get Back Response
echo $clientStream->read();

  Files folder image Files  
File Role Description
Files folder imageContext (6 files, 1 directory)
Files folder imageException (1 file)
Files folder imageFilter (4 files)
Files folder imagefixes (1 file)
Files folder imageInterfaces (6 files, 4 directories)
Files folder imagePsr (2 files)
Files folder imageResource (2 files)
Files folder imageStreamable (6 files, 1 directory)
Files folder imageWrapper (4 files, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file ResourceStream.php Class Class source
Plain text file Streamable.php Class Class source
Plain text file StreamClient.php Class Class source
Plain text file StreamServer.php Class Class source
Plain text file StreamWrapperClient.php Class Class source

  Files folder image Files  /  Context  
File Role Description
Files folder imagefixes (1 file)
  Plain text file aContextStream.fix.php Class Class source
  Accessible without login Plain text file aContextStream.php Aux. Auxiliary script
  Plain text file ContextStreamBase.php Class Class source
  Plain text file ContextStreamHttp.php Class Class source
  Plain text file ContextStreamSocket.php Class Class source
  Plain text file FactoryContextStream.php Class Class source

  Files folder image Files  /  Context  /  fixes  
File Role Description
  Plain text file aContextStream.php Class Class source

  Files folder image Files  /  Exception  
File Role Description
  Plain text file exConnectionTimeout.php Class Class source

  Files folder image Files  /  Filter  
File Role Description
  Plain text file aFilterStreamCustom.php Class Class source
  Plain text file FilterStreamBadword.php Class Class source
  Plain text file FilterStreamPhpBuiltin.php Class Class source
  Plain text file RegistryOfFilterStream.php Class Class source

  Files folder image Files  /  fixes  
File Role Description
  Plain text file SLimitSegment.php Class Class source

  Files folder image Files  /  Interfaces  
File Role Description
Files folder imageContext (1 file)
Files folder imageFilter (3 files)
Files folder imageResource (3 files)
Files folder imageWrapper (2 files)
  Plain text file iResourceStream.php Class Class source
  Plain text file iStreamable.php Class Class source
  Plain text file iStreamClient.php Class Class source
  Plain text file iStreamCommon.php Class Class source
  Plain text file iStreamServer.php Class Class source
  Plain text file iWrapperStreamClient.php Class Class source

  Files folder image Files  /  Interfaces  /  Context  
File Role Description
  Plain text file iContextStream.php Class Class source

  Files folder image Files  /  Interfaces  /  Filter  
File Role Description
  Plain text file iFilterStream.php Class Class source
  Plain text file iFilterStreamCustom.php Class Class source
  Plain text file iRegistryOfFilterStream.php Class Class source

  Files folder image Files  /  Interfaces  /  Resource  
File Role Description
  Plain text file iAccessModeToResourceStream.php Class Class source
  Plain text file iBuilderOfResourceStream.php Class Class source
  Plain text file iMetaReaderOfPhpResource.php Class Class source

  Files folder image Files  /  Interfaces  /  Wrapper  
File Role Description
  Plain text file iRegistryOfWrapperStream.php Class Class source
  Plain text file iWrapperStream.php Class Class source

  Files folder image Files  /  Psr  
File Role Description
  Plain text file StreamBridgeFromPsr.php Class Class source
  Plain text file StreamBridgeInPsr.php Class Class source

  Files folder image Files  /  Resource  
File Role Description
  Plain text file AccessMode.php Class Class source
  Plain text file MetaReaderOfPhpResource.php Class Class source

  Files folder image Files  /  Streamable  
File Role Description
Files folder imageAggregateStreams (1 file)
  Accessible without login Plain text file .todo.php Aux. Auxiliary script
  Plain text file SAggregateStreams.php Class Class source
  Plain text file SDecorateStreamable.php Class Class source
  Plain text file SLimitSegment.php Class Class source
  Plain text file STemporary.php Class Class source
  Plain text file tDecorateStreamable.php Class Class source

  Files folder image Files  /  Streamable  /  AggregateStreams  
File Role Description
  Plain text file ResourceAggregate.php Class Class source

  Files folder image Files  /  Wrapper  
File Role Description
Files folder imageFileAccessControl (2 files)
Files folder imagePsrToPhpResource (1 file)
  Plain text file aWrapperStream.php Class Class source
  Plain text file RegistryOfWrapperStream.php Class Class source
  Plain text file WrapperFileAccessControl.php Class Class source
  Plain text file WrapperPsrToPhpResource.php Class Class source

  Files folder image Files  /  Wrapper  /  FileAccessControl  
File Role Description
  Plain text file ACWOptions.php Class Class source
  Plain text file ACWPermissions.php Class Class source

  Files folder image Files  /  Wrapper  /  PsrToPhpResource  
File Role Description
  Plain text file OptsPsrToPhpResource.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:114
This week:1
All time:8,721
This week:627Up