4

I'm using PHP built in server like so:

$ composer serve
> php -S localhost:8000 -t public/

But it timed out..?

[Symfony\Component\Process\Exception\ProcessTimedOutException]                     
  The process "php -S localhost:8080 -t public/" exceeded the timeout of 300 seconds.

So, I tried to start it up again:

$ composer serve
> php -S localhost:8000 -t public/
[Thu May 26 21:31:51 2016] Failed to listen on localhost:8000 (reason: Address already in use)
Script php -S localhost:8000 -t public/ handling the serve event returned with error code 1

Why is the same port that the server was running on prior to timing out still in use? Can I stop all instances of PHP built in server?

If it matters, below is my composer.json file:

{
    .
    .
    .
    "scripts": {
        "serve": "php -S localhost:8000 -t public/"
    }
}
Martyn
  • 6,031
  • 12
  • 55
  • 121

3 Answers3

6

The problem is that composer has a default timeout after 300 seconds.

Composer ships with the composer-script process-timeout static helper to disable it, just add it on top of your script:

{
    "scripts": {
        "serve": [
            "Composer\\Config::disableProcessTimeout",
            "@php -S localhost:8000 -t public"
        ]
    }
}

To test without changing the script, executing the command you can use --timeout=0, this disables the timeout. In your example the command would look like composer run-script --timeout=0 serve or prefix with the environment parameter like COMPOSER_PROCESS_TIMEOUT=0 composer serve.

More information is also available in Why composer install timeouts after 300 seconds? on site.

hakre
  • 193,403
  • 52
  • 435
  • 836
redshark1802
  • 894
  • 2
  • 12
  • 22
  • 2
    I see, thanks. Might just go back to typing out the full "php -S ..." then as I only preferred the convenience of just typing "composer serve" :) I take it there is no means to put the --timeout value into the composer.json file? – Martyn May 26 '16 at 13:09
4

you can set the process timeout in your composer.json file like this :

  {
    ...
    "scripts": {
      "start": "php -S 127.0.0.1:80 .router.php -t public"
    },
    "config": {
      "process-timeout": 0
    }
  }

and start the web server like this :

$ composer start

azjezz
  • 3,827
  • 1
  • 14
  • 35
0

You can disabled composers timeout.

"scripts": {
    "serve": [
      "Composer\\Config::disableProcessTimeout",
      "@php -S 127.0.0.1:80 -t public"
    ]
}
Eydun
  • 534
  • 1
  • 5
  • 15