Hello guys,

I create an aplicattion for read value from a PLC.
When I used one function socket the php page works fine, but when i put two or more I need around 20secundes to open one php.

Somene Knwos i can improve my code or sockets in php are like this???

The his my code:

<?php
    $dados_recebidos = analisa_dados_dos_turnos($host, $port);
    $ranking = prioridade_dos_turnos($host, $port);
?>
<?php
    function  analisa_dados_dos_turnos($host, $port)
    {   
        $message = "01ff000a4420000002583f00"; // D600 a D662
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");     
        $result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");        
        socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");        
        $result = socket_read ($socket, 1024) or die("Could not read server response\n");       
        socket_shutdown($socket);   
        return $result;
    }
    function prioridade_dos_turnos($host, $port)
    {   
        $message = "01ff000a4420000004291000"; // D1065 a D1079
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");     
        $result = socket_connect($socket, $host, $port) or die("Could not connect to server\n");        
        socket_write($socket, $message, strlen($message)) or die("Could not send data to server\n");        
        $result = socket_read ($socket, 2048) or die("Could not read server response\n");       
        //socket_shutdown($socket); 
        return $result;
    }
?>

What version of PHP are you running? Also, you aren't showing much relevant code.

PHP Version 5.5.15

My just have one more thing, a script for table.

I have constantly two pages like that, running, sending and receive information.

My problem is in sockets, i measure the time for table and i have 0,5 seconds for each.

Why sockets lose so muche time?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.