I have a client application that sends a HTTP request to an Apache server.
The Apache server builds a Tcp / IP connection to a server-side application, forwards the request, and waits for the result and returns it to the client.
So far the whole thing ran over a CGI Skipt in Tcl.
Now I want to eliminate the overhead by repeatedly starting and terminating the Tcl interpreter by using PHP instead of Tcl.
As a zero-beginner in terms of PHP, I've put myself a script together with the help of the whole Internet contributions, which actually works well.
However, I wonder if it is also robust. Could you possibly look over it and tell me your opinion? Are there any subtleties left over? The server-side application can also handle multiple requests at the same time. Can my PHP script handle this too?
Script is attached below.
Thank you very much
Alex
- Code: Select all
<?php
//phpinfo.php
// Test this script
// http://127.0.0.1:80/phpinfo.php?cmd=ServerTest
if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
if(!socket_connect($sock , 'localhost' , 2))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not connect: [$errorcode] $errormsg \n");
}
$s = "";
foreach ($_GET as $key => $value) {
$s = $s . $value . " ";
}
$sock_data = socket_write($sock, $s); //Send data
echo socket_read($sock,1000);
socket_close($sock);
?>