0.0.6 • Published 4 years ago
exec-php v0.0.6
exec-php
Execute PHP function within NodeJS application
Installation
npm install exec-phpUsage
let execPhp = require('exec-php');
execPhp('path/to/file.php', '/usr/bin/php', (err, php, out) => {
// the `php` argument is now contains all php defined functions
php.my_func(arg1, arg2, (err, res, out, print) => {
// `res` argument is now hold the returned value of `my_func` php function
// `print` hold anything that get printed during calling the `my_func` function
})
})Arguments
phpfile::stringPath to user php file.phpbin::stringPath to engine php binary file.callback::functionA function to call after populating the php functions.
The callback function will be called with below arguments:
error::mixedThe error message.php::objectThe php object that hold all php defined functions.printed::stringAll 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::mixedError messageresult::mixedReturned content of user php functionoutput::stringPrinted string on requiring the php file.printed::stringPrinted string on calling user php function.
Example
// file.php
<?php
echo "One";
function my_function($arg1, $arg2){
echo "Two";
return $arg1 + $arg2;
}// app.js
let execPhp = require('exec-php');
execPhp('file.php', (err, php, out) => {
// outprint is now `One'.
php.my_function(1, 2, (err, result, output, printed) => {
// result is now `3'
// output is now `One'.
// printed is now `Two'.
})
})Note
All uppercase function name on PHP will be converted to lowercase on exec-php.
// file.php
<?php
function MyFunction($a, $b){
return $a + $b;
}// app.js
let execPhp = require('exec-php')
execPhp('file.php', (err, php, out) => {
php.myfunction(1, 2, function(error, result){
// result is now 3
})
})ChangeLog
- 0.0.3
- Handle PHP throw error exception
- 0.0.4
- Upgrade tmp module to suppress opsolete functions ( GuilhermeReda )
- Add
noopfunction 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
- Remove deprecated