0

I have a TCP server, written in C++. The server accepts multiple TCP connections and it's able to process then in parallel.

My Apache installation is unable to open more than 1 connection with the server at the same time. If I try to open 2 tabs at the same time, the 2nd one waits for the 1st one to finish and then starts.

BUT, if I run the script from command line/terminal, I am able to open multiple connections.

From the above experiment is clear, the issue is Apache-PHP installation or my PHP code.

The code in question:

<?php
    function connect_($message)
    {
        $port = 13;
        $address = "127.0.0.1";//talk to localhost
        $response = "";

        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($socket !== false)
        {
            $result = socket_connect($socket, $address, $port);
            if ($result !== false)
            {
                socket_write($socket, $message, strlen($message));//send the message
                while ($out = socket_read($socket, 2048)) $response .= $out;//get the response
                socket_close($socket);//exit
            }
        }

        return $response;
    }

    echo connect_('hi');
?>

Can anyone please, exaplain how to setup PHP and Apache in linux and windows to fit my needs?

3
  • Look at stackoverflow.com/questions/13208814/… Commented Oct 27, 2014 at 18:54
  • If I try to open 2 tabs at the same time, the 2nd one waits for the 1st one to finish and then starts. what tabs are you speaking about? Commented Oct 27, 2014 at 19:22
  • @Cthulhu: Tabs with the file index.php. The code of this file is posted above. Commented Oct 27, 2014 at 19:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.