Alternativa correcta (socket daemon)

Alvaro Herrera alvherre en alvh.no-ip.org
Vie Ene 23 14:46:33 CLST 2009


Hector Salinas escribió:

> #!/usr/bin/php -q
> <?php
> set_time_limit (0);
> $address = '192.168.1.235';
> $port = 5000;
> $sock = socket_create(AF_INET, SOCK_STREAM, 0);
> socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, SOL_TCP);
> socket_bind($sock, $address, $port) or die('error bind en la ip');
> socket_listen($sock);
> while (true)
> {
>         $client = socket_accept($sock);
>         socket_getpeername($client, $ip);
>         $input = socket_read($client, 10);
>         echo "\n*******************************";
>         echo "\nNew client connected: {$ip}";
>         echo "\nmemoria usada -->".memory_get_usage();
>         socket_write($client, "A");

socket_close($client); ?

>         unset($input);
>         $contador++;
> }
> socket_close($sock);
> ?>



-- 
Alvaro Herrera                        http://www.advogato.org/person/alvherre
"Industry suffers from the managerial dogma that for the sake of stability
and continuity, the company should be independent of the competence of
individual employees."                                      (E. Dijkstra)


Más información sobre la lista de distribución Linux