apidoc
[ class tree: apidoc ] [ index: apidoc ] [ all elements ]

Class: HTTP_Server

Source Location: /HTTP_Server-0.4.1/HTTP/Server.php

Class Overview


HTTP_Server


Author(s):

Version:

  • 0.4.0

Methods


Child classes:

HTTP_Server_File
This is a basic example of how to use HTTP_Server to build a custom webserver.

Inherited Variables

Inherited Methods


Class Details

[line 86]
HTTP_Server

simple HTTP server class that analyses a request, calls the appropriate request handler (get,post,..) and sends a response

Request handler may be implemented by the developer and have to return an array with reponse code, headers and repsonse body

ever wanted your HTTP server to get content from a database or shared memory instead of files? Now it's possible, if you know a bit of PHP

To create your own HTTP server, just extend this class and implement the methods GET(), POST(), PUT() and DELETE()



[ Top ]


Method Detail

__construct (Constructor)   [line 176]

HTTP_Server __construct( string $hostname, integer $port, [string $driver = 'Fork'])

constructor
  • Access: public

Parameters:

string   $hostname   —  hostname
integer   $port   —  port
string   $driver   —  driver, see Net_Server documentation

[ Top ]

HTTP_Server (Constructor)   [line 163]

HTTP_Server HTTP_Server( string $hostname, integer $port, [string $driver = 'Fork'])

constructor
  • Access: public

Parameters:

string   $hostname   —  hostname
integer   $port   —  port
string   $driver   —  driver, see Net_Server documentation

[ Top ]

GET   [line 331]

mixed GET( integer $clientId, array $headers)

handle a GET request this method should return an array of the following format:

array( "code" => 200, "headers" => array( "Content-Type" => "text/plain", "X-Powered-By" => "PEAR" ), "body" => "This is the actual response" )

  • Return: array containing the response or false if the method handles the response
  • See: HTTP_Server::POST()
  • Access: public

Overridden in child classes as:

HTTP_Server_File::GET()
handle a GET request this method should return an array of the following format:

Parameters:

integer   $clientId   —  id of the client that send the headers
array   $headers   —  request headers

[ Top ]

handleBadRequest   [line 378]

void handleBadRequest( integer $clientId, string $data)

Handler for invalid requests

Implement this in your class.

this method should return an array of the following format:

array( "code" => 200, "headers" => array( "Content-Type" => "text/plain", "X-Powered-By" => "PEAR" ), "body" => "This is the actual response" )

  • Access: public

Parameters:

integer   $clientId   —  client id
string   $data   —  request data

[ Top ]

onReceiveData   [line 200]

void onReceiveData( integer $clientId, string $data)

data was received, i.e. HTTP request sent

Parameters:

integer   $clientId   —  socket that sent the request
string   $data   —  raw request data

[ Top ]

POST   [line 354]

mixed POST( integer $clientId, array $headers)

handle a POST request this method should return an array of the following format:

array( "code" => 200, "headers" => array( "Content-Type" => "text/plain", "X-Powered-By" => "PEAR" ), "body" => "This is the actual response" )

  • Return: array containing the response or false if the method handles the response
  • See: HTTP_Server::GET()
  • Access: public

Parameters:

integer   $clientId   —  id of the client that send the headers
array   $headers   —  request headers

[ Top ]

start   [line 189]

void start( )

start the server
  • Access: public

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:39:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.