Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When PHP built in server crashes, the port is still in use

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/"
    }
}
like image 581
Martyn Avatar asked Aug 31 '25 18:08

Martyn


2 Answers

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.

like image 72
redshark1802 Avatar answered Sep 02 '25 08:09

redshark1802


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

like image 26
azjezz Avatar answered Sep 02 '25 09:09

azjezz