PHP Built-in web server
php.net
php.net
For end users I think the most interesting feature is the ability to provide a router script that can wrap whatever frontend controller your framework is using. And some projects support it natively now. For example, in Symphony2 you download and untar it then just cd into the directory and start php -S localhost:1234 and off you go.
But please, don't ever use this as a replacement for Apache/nginx as a user-visible web server.
That has nothing to do with user code or hosting pages. Most people install PHP using their package manager (ie "yum install php"). Some people and those that maintain those packages, need to compile PHP from source code (PHP is written in C). The guys who develop PHP wrote thousands of tests that make sure that the binary that is compiled works properly. Those are the tests being referenced.
Just off the top of my head, how would you check file_get_contents which can take a url as a parameter?
You can't just throw http://www.google.com/ in there. You might be compiling on a machine that's not on the net, firewalled, etc.
It becomes useful for functionality that normally relies on an external http server to work.
The OP also mentions several more scenarios where it is useful and even necessary.
It took me a while of reading your posts on here to realize who you were, and I note in a recent thread someone even asking how you learned so much about how PHP works...!
Please keep commenting on PHP threads here, the balance and insight is very much welcome!
Languages and frameworks aside, one of the nicest and most newbie friendly parts of Rails is that it's bundled with a webserver, so you can start playing around without having to setup any sort of dev environment.
Edit: I do agree that this should probably not be in the core php interpreter, though. Ideally, it would be a PHP library with a CLI utility, but with PHP's poor culture and adoption towards shared libraries ala composer/rubygems/npm, I think this is the best alternative.
It isn't.
From the page:
"As of PHP 5.4.0, the CLI SAPI provides a built-in web server."
It's part of the CLI SAPI. That's the command line interface to the PHP interpreter. Which makes sense, since that's the only place you'll use it. So if you're using CGI, FastCGI, Apache module, or any other SAPI for regular PHP work, that code is not being loaded.
I'm also pretty sure you can turn it off during compilation of PHP, making it easily removable.
./configure --disable-cli
The CLI is enabled by default, so most distros have this built-in if they have a PHP 5.4 version available.PHP was the first language I learned; the fact that I could deploy it to nearly any shared host [of which there were a lot of freebies] allowed me to rapidly program and debug; which I find was crucial to my initial learning.
Hindsight being 20/20: of course I agree with you, now.
But I'm still not convinced that young me would've been able to use the built in server. I certainly couldn't be bothered to setup Apache (et al) and a working PHP interpreter.
Rails is a bit different, since you learn about the built in webserver when going through their "hello, world" tutorial. If excellent tutorials surface for PHP, then perhaps I can see the "FTP-to-test" pattern being obsoleted.
To me: PHP's greatest asset was that A) I didn't have to setup my own development environment, and B) there were so many [free] development environments already setup!
I'd learn to love setting up servers, but that came far later [in my chronology anyways].
tl;dr: FTP and common PHP setups actually removed a large barrier to entry for a young programmer. I think the "FTP-to-test" anti-pattern was probably one of the more useful ones in my toolkit when it came to my initial learning.
It seems to me like it should be at least as easy to fire up the built-in web server as to learn FTP and sign up for some random shared hosting account, right? That is to say, isn't this even a lower barrier to entry than the FTP approach?
We write Rails apps at work mostly these days, but still have some PHP apps floating around.
Now, instead of having to configure something like Apache just for local development, I've added Procfiles for Foreman to these projects for firing up the PHP webserver along with the rest of the processes the app needs. Much nicer, much more in line with what I enjoy over in Rails-land every day.
This built-in web server has singlehandedly influenced me to actually look at using PHP for projects.
I really don't agree. "php -S localhost:8888" is much, much easier. Let's leave it at that.
I like it is like in the rails/django world
edit: removed completely presumptuous gender pronouns
> django-admin.py startproject myproject
Is that really so hard?
Don't these distros still put php.ini in c:\windows?
You need mysql-python, which depends on some header from mysql-client-dev, which requires some compiling or package, then there's PIL, virtualenv, uwsgi and shit.
Oh wait, you don't have pip on most distros by default. You need to apt-get or wget that.
But you're right about needing PIP.
.. it's using the mongrel http parser wrapped in a PHP extension, so it's pretty fast and reliable: https://github.com/dhotson/httpparser-php
I tried it at work and got pretty significant performance increase since it only has to initialize the framework at server startup instead of every request. We went from a baseline of 70ms to about 2ms per request.
Even with PHP 5.4, I find it more useful for development than the built-in cli-server, since it gives me more flexibility to simulate the various directives in my nginx configuration files (e.g. gzip_static).
PHP-FPM is, though, and it's been around for quite some time.
Furthermore this kind of web server would only be useful for the most basic of projects. As soon as a person dips their toes into anything remotely complex, they're going to need their development server to mirror the production server as closely as possible, especially with things like php.ini and rewrites. So why not just set it up like that to begin with?
There is nothing stopping others getting involved if there were other things they want to see in future PHP versions.
This is open source. You don't "allocate" manpower - people work on whatever they find interesting.