Git Product home page Git Product logo

php-rpm's Introduction

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.

php-rpm's People

Contributors

hjr3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-rpm's Issues

can not compile

linux os

3.10.0-514.10.2.el7.x86_64 

rustc --version

rustc 1.21.0 (3b72af97e 2017-10-09)

run

C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/ LD_LIBRARY_PATH=/root/xx/BIN/usr/lib64 LIBCLANG_PATH=/root/xx/BIN/usr/lib64 cargo build
  1. without dependences updated
   Compiling php-sys v0.1.0 (file:///root/xx/php-rpm/php-sys)
error: linking with `cc` failed: exit code: 1
...
  = note: /root/xx/php-rpm/target/debug/deps/php_rpm-d8aacc3cd1b878d7.0.o: In function `php_rpm::sapi::php_startup':
          /root/xx/php-rpm/src/sapi.rs:148: undefined reference to `zend_signal_startup'
          collect2: error: ld returned 1 exit status


error: aborting due to previous error

error: Could not compile `php-rpm`.

To learn more, run the command again with --verbose.

2.with dependences updated

error[E0614]: type `std::option::Option<&mut php::_IO_FILE>` cannot be dereferenced
  --> src/sapi.rs:77:9
   |
77 |         *handle.fp.as_mut() = fp;
   |         ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `php-rpm`.

To learn more, run the command again with --verbose.

Performance example

In the README.md you point out that the current way of using nginx + php_fpm is flow because of FastCGI. It would be a good idea to have a small section in the readme to show what kind of performance difference this implementation gives you. A simple screenshot of some results compering the same script running with nginx and your new implementation would be good. It would show the need and use of this project very simply.

segmentation fault on linux x86_64

i got this

Compiling php-sys v0.1.0 (file:///root/php-rpm/php-sys)
Compiling php-rpm v0.1.0 (file:///root/php-rpm)
error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:76:14
|
76 | ffi::sapi_globals.sapi_headers.http_response_code = 200;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:79:14
|
79 | ffi::sapi_globals.server_context = context_ptr as *mut c_void;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:84:28
|
84 | let context = ffi::sapi_globals.server_context as *mut ServerContext;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:90:37
|
90 | drop(CString::from_raw(ffi::sapi_globals.request_info.cookie_data));
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:91:14
|
91 | ffi::sapi_globals.server_context = ptr::null_mut();
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:143:10
|
143 | ffi::sapi_globals.request_info = request_info;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:163:24
|
163 | let context = ffi::sapi_globals.server_context as *mut ServerContext;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:171:13
|
171 | if ffi::sapi_globals.headers_sent == 1 {
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:197:24
|
197 | let context = ffi::sapi_globals.server_context as *mut ServerContext;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:227:10
|
227 | ffi::sapi_globals.headers_sent = 1;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:236:24
|
236 | let context = ffi::sapi_globals.server_context as *mut ServerContext;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:263:24
|
263 | let context = ffi::sapi_globals.server_context as *mut ServerContext;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error[E0425]: cannot find value sapi_globals in module ffi
--> src/sapi.rs:325:24
|
325 | let context = ffi::sapi_globals.server_context as *mut ServerContext;
| ^^^^^^^^^^^^ did you mean sapi_globals_id?

error: aborting due to 13 previous errors

error: Could not compile php-rpm.

To learn more, run the command again with --verbose.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.