Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_Http_Server Component Proposal

Proposed Component Name Zend_Http_Server
Developer Notes
Proposers Mat Scales
Matthew Weier O'Phinney (Zend-liaison)
Revision 1.0 - 13 July 2006: First draft.
1.1 - 24 September 2006: Update based on refactoring prototype. Removed Worker class as most of the functionality there had moved back into Server.php and Request.php (wiki revision: 20)

Table of Contents

1. Overview

Zend_Http_Server is an extensible, light-weight HTTP server primarily to allow rapid testing of PHP-based web sites without the need to configure Apache, etc.

I have placed a copy of the current prototype code at

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • Listen for incoming HTTP requests
  • Validate and Encapsulate incoming requests
  • Pass requests to a handler registered at runtime
  • Alternatively, serve simple file requests when no handler is specified
  • Meet (at least) the minimum requirements of the HTTP specification

4. Dependencies on Other Framework Components

  • Zend_Exception
  • Zend_Http_Response

5. Theory of Operation

The user creates an instance of Zend_Http_Server, optionally registers a request handler and/or document root, then tells the server to begin listening. The server continues listening for and processing requests until it is killed. The default request handler will be set up to handle the most common static file types (html,css,gif,jpeg,js) as well as processing PHP scripts.

6. Milestones / Tasks

  • Milestone 1: [DONE] Prototype created serving static content
  • Milestone 2: [DONE] Prototype can serve more than one request at a time
  • Milestone 3: [DONE] Ability to execute "most" PHP scripts
  • Milestone 4: [DONE] Project checked in to SVN
  • Milestone 5: Code meets coding standards
  • Milestone 6: Tests created for everything except Zend_Http_Server->Listen() and the server-start.php script
  • Milestone 7: Environment in which PHP scripts run close enough to Apache to fool existing framework components
  • Milestone 8: Alternative to mod_rewrite for enabling MVC applications
  • Milestone 9: Full unit test coverage
  • Milestone 10: Most obvious security holes fixed (doesn't need to be exhaustive as nobody will be running it in production... right?)
  • Milestone 11: HTTP 1.0 conformance
  • Milestone 12: Mime type support for most common files and localization support provided by Zend_Locale

7. Class Index

  • Zend_Http_Server
  • Zend_Http_Server_Exception
  • Zend_Http_Server_AbstractHandler (the base class for a request handler)
  • Zend_Http_Server_DefaultHandler (the default request handler)
  • Zend_Http_Request (encapsulates a request)

8. Use Cases

  1. Use a helper script to start a server listening on, serving files from /home/mat/www/
    $ php server-start.php -p 8000 -h -d /home/mat/www/

9. Class Skeletons



Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Aug 07, 2006

    <p>Just some guidelines posted previously to the mailing list:</p>

    <p>Andi Gutmans wrote:<br />
    > Providing a full-stack is not in the scope of the framework project. I'm<br />
    > sure many stacks will bundle Zend Framework and will include Web servers<br />
    > etc... E.g. some linux distros.<br />
    > The out-of-the-box HTTP server shouldn't be something aimed at production<br />
    > but at development. </p>

    <p>Eventually, we will have a reasonable set of "how to install" guides for those<br />
    using a *nix distribution that does not have everything conveniently bundled:
    <a class="external-link" href=""></a></p>

  2. Aug 09, 2006

    <p>Yes, runkit is really cool as a technique for running PHP scripts within the PHP Zend_Http_Server. Unfortunately, "This PECL extension is not bundled with PHP." [ <a class="external-link" href=""></a> ], so many ZF developers would not be able to use this. Also, " Instantiating the Runkit_Sandbox class creates a new thread ..." [ <a class="external-link" href=""></a> ]. Historically, there have been a large number of problems with various extensions (both bundled and PECL) in combination with a threaded model. I wouldn't recommend using threads with PHP, unless we could have very tight control over the environment, compilation options, and extensions used.</p>

    <p>However, for those who do have the ability to install runkit, and understand the possible thread safety issues with the particular set of PHP extensions they are using, runkit makes a nice alternative to forking a new process.</p>

    <p>Regarding scope, this isn't a tool for production environments, but a debug aid for development of both ZF components (e.g. Zend_Http) and their unit tests. Also, imagine installing PHP, unpacking the ZF download, and then immediately seeing the results of running the unit test suits, without messing around with configuring a web server. The sample demo applications (there will be more added) could also run "out of the box" using the Zend_Http_Server. If all tests and demo's work "out of the box", but someone wants a more complex LAMP setup, this would give them a known, working configuration (using Zend_Http_Server) to test against and help debug their LAMP configuration.</p>

    <p>So Zend_Http_Server has high value too many people in several situations, even for some who are not planning on using it (those debugging their own LAMP setups).</p>

    1. Sep 20, 2006

      <p>I think I'm happy with the underlying mechanics of the project, and I have a reasonable approximation of a webserver written. I'm using pcntl_fork at the time of each client connection event as an alternative to runkit or (what was I thinking!) exec()ing the php executable.</p>

      <p>Suggestions for milestones would be welcome, though I'll try and think of some for myself.</p>

      <p>I'm happy to release the code I have, either hosting the files myself or perhaps putting it in to the laboratory if you'd like. Until then, I'll keep plugging away at it but you probably wont hear a lot more from me until you have some questions/feedback for me <ac:emoticon ac:name="smile" /></p>

  3. Sep 15, 2006

    <p>Mat Scales wrote:</p>
    <blockquote><p>So the second choice is to start a new php process the old fashioned way - my test code has:</p>

    <p> $output = `php-cgi {$script}`;</p>

    <p>Can anyone spot the problem yet? In order to get $_GET, $_POST, etc. into the user scripts, we have to pass arguments in the environment to the CGI SAPI. The CLI SAPI doesn't generate these variables at all.</p></blockquote>
    <p>Nico Edtinger wrote:</p>
    <blockquote><p>You can add an ini option with '-d auto_prepend_file=' to initialize the superglobals. Maybe you could also search at startup for a exec called php and use 'php -v' to detect if it's a CGI or a CLI (i.e. Mac OS X has the CLI, but no CGI). Of course an option to change the path to the php exec would be nice. Not everyone has PHP 5 as default, but maybe "hidden" in /usr/local</p></blockquote>

  4. Nov 07, 2006

    <ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Feedback</ac:parameter><ac:rich-text-body>
    <p>This proposal is accepted as a useful debugging and development tool for inclusion with the Zend Framework. This component has been assigned to the new "tools" directory folder to distinguish between other library components intended for production deployment.</p></ac:rich-text-body></ac:macro>

  5. Feb 27, 2007

    <p>The process control extension is not enabled by default, also it is not available on windows.</p>

    <p>I realize that calling the php executable to do the threading is a hack, but i don't think this component i very usefull if it is not directly usable on "beginner" development setups, where no non-default extensions are enabled.</p>