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?

SpeedCoder
  • 139
  • 10
  • Look at http://stackoverflow.com/questions/13208814/php-sockets-accept-multiple-connections – Cheery Oct 27 '14 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? – Cthulhu Oct 27 '14 at 19:22
  • @Cthulhu: Tabs with the file index.php. The code of this file is posted above. – SpeedCoder Oct 27 '14 at 19:31

0 Answers0