• This repository has been archived on 04/Jan/2018
  • Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP Rust Process Manager

PHP Rust Process Manager (php-rpm)

Build Status

An experimental process manager that uses Rust's hyper library to act as a frontend for PHP.

Problem

The standard way to run PHP is to use nginx + php_fpm. Not only is this a pain to setup, but FastCGI is not very fast.

Solution

Embed PHP into Rust so that hyper can accept the HTTP request, spawn a thread in which we pass that information off to a PHP script and then have hyper return the HTTP response.

Installation

This package depends on PHP. The default location for the PHP includes is in /usr/include/php. You can set an environment variable PHP_INCLUDE_DIR to override this. The default location for libphp7 is in /usr/lib. You can set an environment variable PHP_LIB_DIR to override this. For details on how to install or compile PHP, see php-sys/README.md. Please note that in order to safely spawn threads with PHP, --enable-maintainer-zts must be used.

The code uses bindgen to dynamically build bindings for PHP 7. If you want to compile against a static libphp7, then specify PHP_LINK_STATIC=1. Using cargo build should give you a working binary.

Usage

Depending on the location of libphp7 you may need to provide LD_LIBRARY_PATH. The first argument to the program is the document root. Currently the index is hardcoded to index.php. Example: PHP_LIB_DIR="/path/to/lib" PHP_INCLUDE_DIR="/path/to/include" LD_LIBRARY_PATH="/path/to/lib" cargo run -- tests/. This will send requests to a script in ./tests/index.php.

The tests/index.php is the entry point of the PHP program. A hyper server listens for new requests and dispatches each request to the PHP engine, which executes tests/index.php. The response headers and body are sent back through hyper and then to the client.

Inspiration

I thought of this idea while working on weldr and thinking about how weldr would be used at my day job (which uses PHP).

Related

See php_fpm.

Thanks

A big thanks to Sara Goleman and her book Extending and Embedding PHP. Also thanks to the people that created bindgen.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

weldr

A HTTP 1.1 proxy written in Rust using tokio.
Rust
218
star
2

mob

Accumulating echo server using Rust's mio
Rust
77
star
3

pecl-gearman

PHP wrapper to libgearman
C
46
star
4

rust-php-ext

Rust library integrated into a PHP extension
C
44
star
5

carp-rs

carp-rs allows a couple of hosts to share common virtual IP addresses in order to provide automatic failover. It is a portable userland implementation of the secure and patent-free Common Address Redundancy Protocol (CARP, OpenBSD's alternative to the patents-bloated VRRP).
Rust
27
star
6

softnet-stat

Parse the `/proc/net/softnet_stat` file into something more readable.
Rust
24
star
7

hyper-timeout

A timeout connector for the hyper client
Rust
22
star
8

rust-get-data-from-url

An example of how to fetch json data from a url, parse the json and get some specific values.
Rust
13
star
9

webservice-demo-rs

A demo webservice compiled as a static binary.
Rust
12
star
10

hal-rs

A pure rust library for generating Hal responses.
Rust
11
star
11

future-mpsc-example

A short example program that uses a future based multi-produer, single-consumer queue.
Rust
8
star
12

gearboot

Simple php gearman worker bootstrap
PHP
7
star
13

crimson

Personal component framework
PHP
6
star
14

udp-no-dns

UDP messages with no DNS lookups
JavaScript
5
star
15

building-better-interfaces

Rust
4
star
16

selecta-score-rs

A more performant version of the selecta scoring algorithm.
Rust
4
star
17

newrelic-rs

New Relic bindings for Rust
Rust
4
star
18

vim-xdebug

Xdebug integration for VIM
Python
4
star
19

dasfd

Simplifying the ember.js development process
JavaScript
2
star
20

Pira

PHP JIRA Soap Library
PHP
2
star
21

itinerant

Simple project template for hacking
PHP
2
star
22

introlink

A chrome extension to Gmail that introduces two people via LinkedIn
JavaScript
1
star
23

pear

PEAR Channel
1
star
24

wp-google-reader-subscriptions

Display Google Reader subscriptions in Wordpress sidebar
PHP
1
star
25

soldr

Rust
1
star
26

hal-rs-demo

A demo web server for the hal-rs library
Rust
1
star