php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75235 Allow multi threads in PHP built in Server
Submitted: 2017-09-20 14:37 UTC Modified: 2021-06-29 13:01 UTC
Votes:15
Avg. Score:4.3 ± 1.0
Reproduced:15 of 15 (100.0%)
Same Version:7 (46.7%)
Same OS:9 (60.0%)
From: mintystark at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Built-in web server
PHP Version: 7.1.9 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mintystark at gmail dot com
New email:
PHP Version: OS:

 

 [2017-09-20 14:37 UTC] mintystark at gmail dot com
Description:
------------
Currently you can't spawn multi threads with the PHP Built in Server.  I know that creating such feature would take a lot of time and might require additional support from other packages, etc.  However, you can spawn multiple instances of the PHP Built in Server by launching it to other Ports.

So I am suggesting that all is needed is the ability for the Built in Server to auto detect an additional process and assign that process to any available ports that the built in server has access to.

Ex.
php -S localhost:8000-80010 -t foo/

Or (Preferably)
php -S localhost:8000 -threadports 10 -t foo/

Or something like that
Which would spawn 10 additional instances of the Built in server from port 8001 to 8010.
Then if I am running a process on 8000 and make an addition process request on port 8000.
it will pass the process to the next available port 8001.

Like if I do a curl request to port 8000 or need any additional process requests like using exec() or shell_exec() etc.  

Currently running those commands with the built in web server on an existing process halts the request until the command finishes.  Even if you add the "&" at the end of the command which should return the request immediately.

Example:
shell_exec('php -f "class.php" > /dev/null 2>&1 & echo $!);

Thanks


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-20 14:51 UTC] requinix@php.net
What you're describing won't work: since the server is single-threaded, it won't be able to see the "additional process request". Faked multi-threading using multiple processes on multiple ports is not really a good solution either.

Multi-threading is probably the correct answer here, or at least some other sort of master/slaves architecture. I don't see any open *requests* to add that so I think I'll leave this as is, but as far as I know there's still no desire to do it because the built-in server is designed as a quick convenience and not a real web server.
 [2017-09-20 20:57 UTC] mintystark at gmail dot com
Then I will make a new request for it.

I do appreciate the Built in Server and it has made quick development very nice, but I have been finding myself having to setup Nginx many times because my tests require multi threading.  At which point the built in server hasn't been useful.

I have had to start up multiple ports and send the additional commands to the other ports, (ie cUrl) which works fine.  However, running functions like shell_exec() does not allow for selecting which port so I have to use nginx.

I understand that my scenario might be a use case, but I have found other comments requesting that the Built in server should allow multi threading so I think it would be very beneficial.

Thanks

https://stackoverflow.com/questions/39842170/load-balancing-php-built-in-server
https://bugs.php.net/bug.php?id=67884
https://stackoverflow.com/questions/29173953/php-built-in-server-cant-curl
https://bugs.php.net/bug.php?id=66690
 [2017-09-20 21:02 UTC] requinix@php.net
67884 was a bug report. I considered closing this one as NAB/wontfix like it based on precedence but decided against it.
66690 was an unrelated issue.

> Then I will make a new request for it.
You already have a request for it: this one.

> shell_exec() does not allow for selecting which port
Of course not: shell_exec has nothing to do with networking. I'm not sure what port you're trying to select with it but I'm pretty sure it is actually possible.
 [2021-06-29 13:01 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-06-29 13:01 UTC] cmb@php.net
As of PHP 7.4.0, the built-in Webserver supports multiple workers
according to the environment variable PHP_CLI_SERVER_WORKERS[1].
That should be as good as a multi-threaded Webserver on platforms
which support fork(2).

[1] <https://www.php.net/manual/en/features.commandline.webserver.php>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC