0

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;
    }
?>
2
Contributors
2
Replies
22
Views
2 Years
Discussion Span
Last Post by sergio_pb
0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.