Skip to content
Servlet-based PHP server built above nanoserv.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
nanoserv-php5.3
src
LICENSE
README.md
quartz.php

README.md

Quartz

Quartz is a servlet-based HTTP server written in PHP5.3 and built above nanoserv.
What's interesting about Quartz is that it does not use a templating, MVC or classical architectures used with PHP, but acts as a web container.
And what's funnier than writing servlets in PHP rather than in Java?

Just download quartz.php and the nanoserv-php5.3 folder, put them at the same place, and do php -q quartz.php to start it!

Take a look at the wiki to know how to work with Quartz: https://github.com/lngns/Quartz/wiki
Or check nanoserv, the awesome library Quartz uses: http://nanoserv.si.kz

Examples

Here's an example of a Quartz Servlet wich doGet() method is called when a GET /foo request is received:

class Servlet_foo extends Quartz_Servlet
{
  private $counter;
  public function init()
  {
    $this->counter = 0;
    return true;
  }
  public function doGet(Quartz_HTTP_Request $req)
  {
    if($this->counter == 10) $this->counter = 0;
    $counter = $this->counter++;
    return "<!DOCTYPE html>
      <html>
        <head>
          <title>Quartz</title>
        </head>
        <body>
          <p>
            Hello World from Servlet_foo::doGet() located at 
            ".Quartz::build_path("www/foo.php")."
          </p>
          counter: ".$counter."
        </body>
    </html>";
  }
}

Here's an example of servlet using the same function for both GET and POST requests:

class Servlet_bar extends Quartz_Servlet
{
  public function init()
  {
    $this->post_handler = "doGet";
    return true;
  }
  public function doGet(Quartz_HTTP_Request $req)
  {
    $html = "<!DOCTYPE html><html><body>";
    if(($user = $req->Get("user")) !== false || ($user = $req->Post("user")) !== false)
      $html .= "Hello ".$user."!";
    else
      $html .= "Hello World!";
    $html .= "</body></html>";
    return $html;
  }
}

Here's a servlet alternating its handlers:

class Servlet_baz extends Quartz_Servlet
{
  public function init()
  {
    $this->get_handler = 'first';
    return true;
  }
  public function first(Quartz_HTTP_Request $req)
  {
    $this->get_handler = 'second';
    return 'First.';
  }
  public function second(Quartz_HTTP_Request $req)
  {
    $this->get_handler = 'first';
    return 'Second.';
  }
}
You can’t perform that action at this time.