iqbalfn / exec-php Goto Github PK
View Code? Open in Web Editor NEWExecute PHP function within NodeJS application
License: MIT License
Execute PHP function within NodeJS application
License: MIT License
Specially in Windows, where folders usually have white spaces in its names.
Is there any way i can call a function within a php class?
I was wondering if there are any way to get the error generated in PHP instead of a "Error: Command failed: /bin/sh -c /usr/bin/php [...]".
So far there are not tests run for commits and PRS.
It would be great to have Travis CI for testing all commits and PRs.
Thank you for exec-php, it's been very helpful.
I'm using it in my mocha tests, but I'm getting deprecation warnings both for os.tmpDir() is deprecated. Use os.tmpdir() instead.
and Calling an asynchronous function without callback is deprecated.
.
Here are some stack traces:
(node:53568) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
at makeCallback (fs.js:127:12)
at Object.fs.unlink (fs.js:1049:14)
at /path/to/my/app/node_modules/exec-php/lib/cli.js:53:20
at ChildProcess.exithandler (child_process.js:267:7)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
(node:53568) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
at Object.<anonymous> (/path/to/my/app/node_modules/exec-php/node_modules/tmp/lib/tmp.js:25:10)
at Module._compile (module.js:643:30)
at Module._extensions..js (module.js:654:10)
at Object.require.extensions.(anonymous function) [as .js]
I am working on an app that responds to certain status changes. Whenever an order changes its status to 2, I run a php file with
execPhp("../php/tasks/task2.php", function(error, php, outprint) {
console.log(outprint)
if (error) {
console.log(error)
}
})
The first time this executes just like I want to, but if another order changes to status 2, the output of the first time running is repeated without the php script being executed again.
I tested this with the following code in task2.php
$randnr = rand(0, 1000);
mkdir($config['tmp'].$randnr, 0777, true);
And only one dir is made after changing multiple orders to status 2.
Is this normal or am I missing something?
Hi,
It's possible to call a php function with uppercase ? like myFunctionLikeThis()
.
I've an error on node when i use uppercase.
Thanks
I im using this library and works perfect, but I want to create a PDF file, and the easy way to me its use a MPDF library.
How I can return a file?
I have this
execPhp('script.php', function(error, php, outprint){
php.my_function( function(err, result, output, printed){
res.json(result);
});
});
When I return the file appears this error
undefined:1
SyntaxError: Unexpected end of input
at Object.parse (native)
at C:\abria-backend\node_modules\exec-php\lib\cli.js:51:33
at ChildProcess.exithandler (child_process.js:204:7)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:829:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
My sample php script
<?php
include("mpdf/mpdf.php");
function my_function(){
$mpdf = new mPDF();
// Write some HTML code:
$mpdf->WriteHTML('Hello World');
// Output a PDF file directly to the browser
$mpdf->Output();
}
?>
Thanks
Hi,
1|report | SyntaxError: Unexpected token u in JSON at position 0
1|report | at JSON.parse ()
1|report | at exec (/PUBLIC/socket/node_modules/exec-php/index.js:71:26)
1|report | at ChildProcess.exithandler (child_process.js:285:7)
1|report | at ChildProcess.emit (events.js:198:13)
1|report | at maybeClose (internal/child_process.js:982:16)
1|report | at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
where is the problem? The data I sent is the same as yours.
I was getting app crash coz of the high number of fd that linked to my app pid.
after going through the code I can see you only unlink the file which doesn't close the file, only removed it
at:
Line 57 in 711fa5b
Line 58 in 711fa5b
we need to add the following at L56:
fs.close(fd,closeCB);
fs.close(fds,closeCB);
Hi,
I am trying to call a function in PHP file which instantiates a class which contains a set of functions and returns said class. However, when I call the getClass function, the result from the JavaScript code is an empty object.
Can this library handle PHP classes?
class upgrade_v5
{
function __referringUrl($input)
{
$value = array_key_exists('campaign_id', $input) && isset($input['campaign_id']) && $input['campaign_id'] !== false && $input['campaign_id'] !== '' ? $input['campaign_id'] : '';
return $value;
}
}
function getPoster()
{
$poster = new upgrade_v5();
return $poster;
}
execPhp('execPhpTest.php', function(error, php, outprint){
php.getposter(function(error, result){
console.error(error);
console.log(result);
});
});
Console output:
false {}
If a php script throws an exception, php-exec errors. I had expected the error parameter to contain the error information.
/Users/garysmart/Documents/Projects/Gravme/code/trunk/haraka/node_modules/exec-php/index.js:46
for(var i=0; i<result.length; i++){
^
TypeError: Cannot read property 'length' of undefined
at /Users/garysmart/Documents/Projects/Gravme/code/trunk/haraka/node_modules/exec-php/index.js:46:30
at /Users/garysmart/Documents/Projects/Gravme/code/trunk/haraka/node_modules/exec-php/lib/cli.js:49:28
at ChildProcess.exithandler (child_process.js:751:5)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1008:16)
at Process.ChildProcess._handle.onexit (child_process.js:1080:5)
My js code looks like this:
var execPhp = require('exec-php'); // https://www.npmjs.com/package/exec-php
var script = "test.php";
execPhp(script, '/usr/bin/php', function(error, php, output) {
console.log(error);
console.log(php);
console.log(output);
});
I had a large script that threw an exception, but can replicate it with this simple php script:
<?php
throw new Exception("TEST");
I was trying to execute php file but got some errors
<?php
echo 'This is php file';
function my_function($voipToken){
$deviceToken = $voipToken;
echo $deviceToken;`
This is I called it from Node js script
execPhp('php/app.php', function(error, php, outprint){
console.log(error)
php.my_function(deviceToken, function(err, result, output, printed){
if (result) {
console.log("This is message " + printed)
console.log("This is result " + result)
} else {
console.log("false sending " + result)
}
Basically what I want to do over here is to get data into node server js, data which is returned from a function which is written into a Zend model.
My node js server code is as below:
var socket = require( 'socket.io' );
var express = require( 'express' );
var http = require( 'http' );
var execPhp = require('exec-php');
var app = express();
var server = http.createServer( app );
var io = socket.listen( server );
execPhp('../application/modules/front/models/Dbtable/Postcontent.php',
function(error, php, outprint){
php.fetchEntryAll(function(error, result){
io.sockets.emit('showfeeds', result);
});
});
server.listen( 7000 );
so when I tried to execute above code it gives me error like below:
Error: Command failed: PHP Fatal error: Class 'Zend_Db_Table_Abstract' not found in /Data/www/XXX/application/modules/front/models/Dbtable/Postcontent.php on line 3
same code works when I use core PHP instead of Zend.
So I believe that we can't use OOP stuff with exec-php.
Is there any solution here?
<?php
echo "Hello $name";
var execPhp = require('exec-php');
var locals = { name: "World" };
execPhp('path/to/php/file.php', '/path/to/php/bin/php', locals, function(error, php, output){
output
// => Hello World
});
How can i edit the php.ini file of this if i have used it as a node package in my node project.
I need to make a api hit by means of curl and it says fatal error function not found.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.