Download the PHP package tijmen-wierenga/async-php-server without Composer
On this page you can find all versions of the php package tijmen-wierenga/async-php-server. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tijmen-wierenga/async-php-server
More information about tijmen-wierenga/async-php-server
Files in tijmen-wierenga/async-php-server
Package async-php-server
Short Description Fast asynchronous PHP server
License MIT
Informations about the package async-php-server
Asynchronous PHP Server
This package contains an easy to use asynchronous PHP server which you can setup in minutes. Get rid of bootstrapping your entire application on every request!
The server is build with the awesome React PHP components which enables you to speed up your application. Do all the necessary bootstrapping of your app only once, and keep it in memory as all requests are being handled in an asynchronous way.
Installation
There are two ways to install the server:
Manual
Install the repository using GIT:
Composer
Example
The repository comes with an example server which you can run locally. To run the example server simply run it in php:
Or run it with Docker (make sure you mount the correct volume to the container):
To check if the server is running, check the logs:
This should print: Server is running on 0.0.0.0:9000
To test the server, simply send a CURL command to the container:
If everything is working correctly, you'll receive a 200 OK
JSON Response containing the posted data.
Usage
In order to run the asynchronous server you need to pass it three required instances:
- Connection
- RequestHandler
- Parser
Connection
A connection is necessary for the server to know to bind to. Create a new Connection instance and specify the port and IP address:
RequestHandler
The RequestHandler is basically a wrapper for the application. The handle
method receives the request and should return a response (even on an error).
You can find a very simplistic example of a RequestHandler below:
This RequestHandler will respond with "Hello World!" anytime it receives a request.
Parser
The parser is used to parse the Request and Response body. A parser can simply format any given data into a specific format. This package comes with a DefaultParser class which is a wrapper class for nathanmac/parser. Instantiate the DefaultParser like this:
Bringing it all together
Known issues
- The server can only handle a certain amount of content types
- The server cannot handle file uploads
Docker
TODO