7

I have encountered a problem using php's built in webserver, in that it appears to only allow a single concurrent connection.

I discovered this when testing some concurrent ajax requests which all appeared to complete at the same time.

This isnt a big deal, as i can always fire up apache (which is how i came to above conclusion), but i have gotten used to running php directly from my IDE.

Is there any way to increase this, or is it a php limitation?

my example code that blocks with the inbuilt server but works fine on apache:

        $.ajax({
            type: "POST",
            url: slow.php,
            data: "",
            success: function(data){
                clearInterval(checkid);
                console.log('slow call finished');
            }
        });

        checkid = setInterval(function(){
            $.get('somefile.txt', function(data){
                console.log('quick call finished');
            });
        },1000);


        //slow.php
        sleep(10);
        echo 'all done';
Steve
  • 20,703
  • 5
  • 41
  • 67
  • 1
    PHP has a built-in webserver? As far as I know, it runs on a webserver like Apache or nginx. – Bailey Herbert Jul 31 '14 at 15:07
  • 1
    @BaileyHerbert you know wrong! Its a basic development server available since php 5.4: http://php.net/manual/en/features.commandline.webserver.php – Steve Jul 31 '14 at 15:08
  • Depending on what you're trying to fetch, you could just duplicate the dev server. I've done this for handling api requests while simultaneously handling image serving. Obviously only makes sense for quick development. – Justin Dalrymple Apr 10 '20 at 15:43

1 Answers1

10

Quoting from the manual:

PHP applications will stall if a request is blocked.

So yes, it's single threaded. Also, it's just an aid for development, in practice you'll seldom want to use it anyway as it doesn't support important external technologies like FallbackResource, mod_rewrite and .htaccess which are intertwined with most web projects.

Modern IDEs like PhpStorm support automatic deployment on save to local and remote testing webservers, which is far more practical in projects larger than a handful of files.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
  • yes i read that, just hoping that it might be configurable option. Never mind! And i actually use phpstorm, but its annoying having to set up virtual host entries and edit hosts file to enable working out of my preferred folders for quick projects. Thanks though – Steve Jul 31 '14 at 15:19
  • 1
    If you do a lot of projects, consider introducing a wildcard TLD in your local DNS server (http://projectname.internal) and then use [VirtualDocumentRoot](http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html#virtualdocumentroot) to never have to write a single vhost entry again. It's how we work here in a professional internet bureau with 9 active developers. – Niels Keurentjes Jul 31 '14 at 15:46
  • And in general PHP is single threaded...meaning that when Apache starts PHP request...it starts a separate process every time...something to understand during development – Zilvinas Dec 03 '16 at 02:31
  • 1
    @Zilvinas that is 100% incorrect. PHP normally either runs as an Apache module or via FPM workers. In both cases the same executing process is recycled thousands of times depending on your settings to minimize OS overhead. Without this mechanism performance would degrade drastically and dramatically. – Niels Keurentjes Dec 03 '16 at 07:50