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;
}
?>