PHP code example of devsmine / pnet

1. Go to this page and download the library: Download devsmine/pnet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devsmine / pnet example snippets


 use Devsmine\pnet\network\Socket;
try{
           $server = new Socket(SERVER_IP, SERVER_PORT, [
               'bind' => true,
               'listen' => true
           ]);
           echo "Server initiated... \n";
           $server->startServer('', function($message) {
               $response=[$message]; // return your custom message;
               $response =json_encode($response);
               return $response;
           }, 'closure');

       }catch (\Exception $exception){
           echo $exception->getMessage()."\n";
       }

$request = 1;
$start = microtime(true);
for($i =0; $i<$request; $i++) {
	$socket = new Socket(SERVER_IP, SERVER_PORT, ['connect' => true]);
 	$response = $socket->send(json_encode(["hello"]));
	 echo $response;
	$socket->close();
}
echo "\n".'Execution Time: ' . (microtime(true) - $start) . "\n";