System_Socket
[ class tree: System_Socket ] [ index: System_Socket ] [ all elements ]

Source for file unix-listener.php

Documentation is available at unix-listener.php

  1. <?php
  2.  
  3. /**
  4. * Simple unix domain socket listener
  5. * $Id: unix-listener.php,v 1.4 2004/04/25 16:31:19 mike Exp $
  6. */
  7.  
  8. require_once 'System/Socket/Creator.php';
  9.  
  10. PEAR::setErrorHandling(PEAR_ERROR_DIE"Fatal PEAR Error: %s\n");
  11.  
  12. /**
  13. * Create a System_Socket_Listener object with the specified options passed
  14. * through to the underlying System_Socket.  Most of the used parameters
  15. * are typical for a unix domain socket listener.
  16. * Note that unix domain sockets are not available on Win32.
  17. */
  18. $sock &System_Socket_Creator::createListener(
  19.     array(  'proto'     => SOL_SOCKET,
  20.             'domain'    => AF_UNIX,
  21.             'type'      => SOCK_STREAM,
  22.             'address'   => '/tmp/pear.sock',
  23.             'port'      => 0,
  24.     )
  25. );
  26. /**
  27. * Alternatively:
  28. * <code>
  29. *   $sock = &System_Socket_Creator::createUnixListener('/tmp/pear.sock');
  30. * </code>
  31. */
  32.  
  33. /**
  34. * Loop while we have a socket resource
  35. */
  36. while ($sock->hasSocket{
  37.     /**
  38.     * Get a System_Socket_ConnectionPool object holding our connected clients.
  39.     */
  40.     $pool &$sock->getReadableClients();
  41.     /**
  42.     * Walk through all connections and display the data the clients sent.
  43.     * If we catch a "exit" stop the socket server.
  44.     */
  45.     while ($conn &$pool->shift()) {
  46.         $line $conn->readLine();
  47.         if (trim($line== 'exit'{
  48.             echo "EXITING!\n";
  49.             $sock->close();
  50.             break;
  51.         }
  52.         echo "CLIENT SAYS: $line";
  53.     }
  54.     flush()ob_flush();
  55.     sleep(1);
  56. }
  57.  
  58. ?>

Documentation generated on Mon, 11 Mar 2019 10:15:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.