PHPackages                             phastlight/phastlight - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. phastlight/phastlight

ActiveLibrary[CLI &amp; Console](/categories/cli)

phastlight/phastlight
=====================

Phastlight -- Asynchronous, event-driven command line tool and web server written in PHP 5.3+ inspired by Node.js

v0.3.0.1(12y ago)16212210MITPHPPHP &gt;=5.3.0

Since Feb 23Pushed 12y ago23 watchersCompare

[ Source](https://github.com/phastlight/phastlight)[ Packagist](https://packagist.org/packages/phastlight/phastlight)[ Docs](https://github.com/phastlight/phastlight)[ RSS](/packages/phastlight-phastlight/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (16)Used By (0)

Phastlight
==========

[](#phastlight)

Phastlight is an asynchronous, event-driven command line tool and web server written in PHP 5.3+ inspired by Node.js

Phastlight is built on top of libuv, the same library used behind Node.js.

[Install Phastlight](#installation)

[Benchmark against Node.js](#simple-http-server-benchmarked-with-php-559-and-nodejs-v01025)

At this time, Phastlight is on its very early development phrases,it currently supports the following features:

- [Dynamic method creation](#dynamic-method-creation)
- [Module Creation](#module-creation)
- Event
    - [Event Emitting](#event-emitting)
- Error and Exception Handling
    - [Error Handling and system.error event](#error-handling)
    - [Exception Handling and system.exception event](#exception-handling)
- HTTP
    - [Async HTTP Server](#simple-http-server-benchmarked-with-php-559-and-nodejs-v01025)
    - PHP server variables simulation on HTTP Request

        Phastlight simulates the following PHP server variables on each HTTP Request:

        ```
        $_SERVER['SERVER_PORT']
        $_SERVER['SERVER_ADDR']
        $_SERVER['REMOTE_ADDR']
        $_SERVER['HTTP_HOST']
        $_SERVER['REQUEST_METHOD']
        $_SERVER['REQUEST_URI']
        $_SERVER['PATH_INFO'],
        $_SERVER['HTTP_USER_AGENT']
        ```
- Timer
    - [Async Timer](#server-side-timer) similar to
- Process
    - [Next Tick](#process-next-tick) similar to [http://nodejs.org/api/process.html#process\_process\_nexttick\_callback](http://nodejs.org/api/process.html#process_process_nexttick_callback)
- Child Process
    - [executing command](#execute-command-in-child-process)
- Console
    - [Log message to the console](#console-log-like-javascript) similar to Console.log in Javascript
- File System:
    - [read content of directory asynchronously](#file-system--reads-the-contents-of-a-directory-in-async-fashion)
    - [open file asynchronously](#file-system-create-a-new-file-and-write-content-to-it)
    - [read file asynchronously](#file-system--reads-the-contents-of-a-directory-in-async-fashion)
    - [write file asynchronously](#file-system-create-a-new-file-and-write-content-to-it)
    - [close file asynchronously](#file-system-on-each-http-request-append-a-message-to-a-file-named-weblog-in-async-fashion)
    - [rename file asynchronously](#rename-file-asynchronously)
    - [remove file asynchronously](#remove-file-asynchronously)
    - [get file stat asynchronously](#get-file-stat-asynchronously)
- Asynchronous Network Wrapper
    - [TCP Server](#tcp-server)
    - [TCP Connection](#tcp-connection)
- Operating System
    - [Get CPU Information](#operating-system-information)
    - [Get Memory Information](#operating-system-information)
- Cluster
    - [Worker forking](#working-forking)

More features will be on the way, stay tuned...

Phastlight Application Examples:

- [Mult-Tasking in one single event loop](#handle-multiple-tasks-in-one-single-event-loop)
- [Simple Microframework on top of Phalcon PHP Framework Routing Component](#integrating-phastlight-with-phalcon-php-framework-routing-component)
- [Working with Symfony2 HTTP Foundation Request and Response component](#output-html-with-symfony2-http-foundation-component)
- [Simple asynchronous MYSQL query through dbslayer](#simple-asynchronous-mysql-query-through-dbslayer)
- [Simple asynchronous Memcache get and set](#asynchronous-memcache-get-and-set)
- [Simple asynchronous Redis get and set](#asynchronous-redis-get-and-set)

At this phrase, phastlight is good for high concurrency, low data transfer, non cpu intensive web or moble applications.

\##Installation:

Tested on:

- CentOS 6.2 64bit with gcc 4.4.x
- Mac OS 10.8 with gcc 4.2.1

#### install with the installation script

[](#install-with-the-installation-script)

```
curl -sS https://raw.github.com/phastlight/phastlight/master/scripts/install.sh | sh

```

This will install phastlight to /usr/local/phastlight directory, and the phastlight executable will be at /usr/local/bin/phastlight

To install phastlight executable to a different directory, for example, the ~/bin directory, do:

```
curl -sS https://raw.github.com/phastlight/phastlight/master/scripts/install.sh > phastlight_install.sh
sh phastlight_install.sh --phastlight_executable_path=~/bin
rm -f phastlight_install.sh

```

#### To run the server, do phastlight \[server file full path\]

[](#to-run-the-server-do-phastlight-server-file-full-path)

### Dynamic method creation

[](#dynamic-method-creation)

Phastlight allows dynamic method creation, in the example below, we create a hello method in the system object

```
