exec-php
Execute PHP function within NodeJS application
Installation
npm install exec-php
Usage
let execPhp = require('exec-php');
execPhp('path/to/file.php', '/usr/bin/php', (err, php, out) => {
php.my_func(arg1, arg2, (err, res, out, print) => {
})
})
Arguments
phpfile::string
Path to user php file.phpbin::string
Path to engine php binary file.callback::function
A function to call after populating the php functions.
The callback
function will be called with below arguments:
error::mixed
The error message.php::object
The php object that hold all php defined functions.printed::string
All printed string while populating php functions.
php Arguments
All user defined function on php engine will be appended to php
argument of
the caller. The function will be lower case. You can now call the function
normally with additional last argument is the callback function to get response
of the php functions call with below arguments:
error::mixed
Error messageresult::mixed
Returned content of user php functionoutput::string
Printed string on requiring the php file.printed::string
Printed string on calling user php function.
Example
<?php
echo "One";
function my_function($arg1, $arg2){
echo "Two";
return $arg1 + $arg2;
}
let execPhp = require('exec-php');
execPhp('file.php', (err, php, out) => {
php.my_function(1, 2, (err, result, output, printed) => {
})
})
Note
All uppercase function name on PHP will be converted to lowercase on exec-php
.
<?php
function MyFunction($a, $b){
return $a + $b;
}
let execPhp = require('exec-php')
execPhp('file.php', (err, php, out) => {
php.myfunction(1, 2, function(error, result){
})
})
ChangeLog
- 0.0.3
- Handle PHP throw error exception
- 0.0.4
- Upgrade tmp module to suppress opsolete functions ( GuilhermeReda )
- Add
noop
function to support the new node callback standard
- 0.0.5
- Close temp file pointer on removing the file ( MHDMAM )
- 0.0.6
- Remove deprecated
module.parent
( Jakub Zasański ) - Upgrade deprecated dependencies