File tree Expand file tree Collapse file tree 4 files changed +46
-0
lines changed
Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 44 requests from node's http server.
55* Support passing "command-line arguments" to allow the embedded PHP
66 to execute scripts using PHP's CLI interface.
7+ * Add a simple ` php-embed ` CLI script for easy testing.
78* Allow PHP to invoke asynchronous JavaScript functions synchronously
89 by passing a ` Js\Wait ` object where the callback would go. This
910 blocks the PHP event loop (naturally) but not the JavaScript one.
Original file line number Diff line number Diff line change @@ -54,6 +54,19 @@ php.request({
5454}).done ();
5555```
5656
57+ ## Running command-line PHP scripts
58+
59+ The ` php-embed ` package contains a binary which can be used as a
60+ drop-in replacement for the ` php ` CLI binary:
61+
62+ ``` sh
63+ npm install -g php-embed
64+ php-embed some-file.php argument1 argument2....
65+ ```
66+
67+ Not every feature of the PHP CLI binary has been implemented; this
68+ is currently mostly a convenient testing tool.
69+
5770# API
5871
5972## php.request(options, [ callback] )
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+ 'use strict' ;
3+ // Very simple CLI wrapper, to allow php-embed to be used as a replacement
4+ // for the `php` binary.
5+ var php = require ( '../' ) ;
6+
7+ // XXX here we might eventually do some preprocessing of the command line
8+ // like the PHP CLI does.
9+ // For now assume the first argument is the script to run.
10+
11+ var args = process . argv . slice ( 0 ) ;
12+ if ( args . length < 3 ) {
13+ console . error ( 'PHP filename needed.' ) ;
14+ process . exit ( 1 ) ;
15+ }
16+ args . shift ( ) ; // Remove the path to the node interpreter
17+ args . shift ( ) ; // Remove the path to this script
18+ var phpfile = args [ 0 ] ;
19+
20+ // XXX an `exit(2)` in the PHP script will cause the request to bailout
21+ // and throw a JS exception, which will then cause a non-zero exit
22+ // code from node as well -- but with a lot of extra noise on the
23+ // console. We should figure out how to catch this case in PHP,
24+ // wrap the exit code appropriately, then catch the exception here
25+ // and unwrap the exit code.
26+ php . request ( {
27+ file : phpfile ,
28+ args : args ,
29+ } ) . done ( ) ;
Original file line number Diff line number Diff line change 55 "homepage" : " http://github.com/cscott/node-php-embed" ,
66 "author" : " C. Scott Ananian <cscott@cscott.net>" ,
77 "main" : " lib/index" ,
8+ "bin" : {
9+ "php-embed" : " ./bin/php-embed.js"
10+ },
811 "keywords" : [
912 " php" ,
1013 " hhvm"
You can’t perform that action at this time.
0 commit comments