tommasov

Socket_recv

Oct 15th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. //$this->resource è la mia socket
  2.  
  3. //Ho dovuto impostare queste opzioni array( "sec" => 1, "usec" => 0 ), altrimenti tutto restava in attesa senza ritornare niente.
  4. socket_set_option( $this->resource, SOL_SOCKET, SO_RCVTIMEO, array( "sec" => 1, "usec" => 0 ) );
  5.  
  6. //Inizializzo le variabili
  7. $buf    = "";
  8. $output = "";
  9.  
  10. //Fino a quando socket_recv è true ciclo 1024 byte alla volta
  11. while ( false !== socket_recv( $this->resource, $buf, 1024, MSG_WAITALL ) ) {
  12.     if ( $buf != null ) {
  13.         //Appendo i dati stringa letti alla variabile $output
  14.         $output .= $buf;
  15.     }
  16. }
  17.  
  18. //Ritorno il tutto
  19. return $output;
Advertisement
Add Comment
Please, Sign In to add comment