Interprocess communication with Apache and PHP

Alles, was PHP betrifft, kann hier besprochen werden.

Interprocess communication with Apache and PHP

Postby mp2013 » 01. November 2016 18:54

Hi,

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);

?>
mp2013
 
Posts: 3
Joined: 01. November 2016 18:45
XAMPP version: 2.4
Operating System: Windoows 7

Return to PHP

Who is online

Users browsing this forum: No registered users and 2 guests