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");
>         unset($client);
>         unset($input);
>         $contador++;
> }
> socket_close($sock);
> ?>

Hmm, leyendo la pagina sobre variables en el manual de PHP te
recomendaria que pusieras las variables que son "locales" dentro de una
funcion.  No queda para nada claro que la memoria se libere al hacer un
"unset".  O sea, algo asi:

#!/usr/bin/php -q
<?php

function do_client_stuff( ... )
{
         $client = socket_accept($sock);
         socket_getpeername($client, $ip);
         $input = socket_read($client, 10);
         echo "\n*******************************";
         echo "\nNew client connected: {$ip}";
         socket_write($client, "A");
        socket_close($client);
}

 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)
 {
          do_client_stuff($sock);
         $contador++;
         echo "\nmemoria usada -->".memory_get_usage();
 }
 socket_close($sock);
?>

-- 
Alvaro Herrera                               http://www.PlanetPostgreSQL.org/
"I think my standards have lowered enough that now I think 'good design'
is when the page doesn't irritate the living f*ck out of me." (JWZ)

Responder a