Giter Club home page Giter Club logo

exec-php's People

Contributors

guilhermereda avatar iqbalfn avatar karlosq avatar mhdmam avatar rafajaques 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

Watchers

 avatar  avatar

exec-php's Issues

PHP classes

Is there any way i can call a function within a php class?

Get PHP error

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 [...]".

add and enable Travis CI

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.

Deprecation warnings

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] 

When calling a php script a second time, it doesn't execute the code again

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?

Error in some files

SyntaxError: Unexpected end of JSON input

I am using version 0.0.5

And this is error
screen shot 2562-01-30 at 3 44 06 pm

This is code in Node jS

execPhp('test.php', function(error, php, outprint){

});

Test.php

<?php
echo "One";

How I can return a file?

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

Not Working

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.

app crash due to not closing file

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:

fs.unlinkSync(tmpParam);

and here:
fs.unlinkSync(tmpResult);

we need to add the following at L56:

fs.close(fd,closeCB);
fs.close(fds,closeCB);

Working with PHP Classes

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 {}

JS Error if PHP script throws exception

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");

Cannot read property 'my_function' of undefined

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)
        }

How to use exec-php in MVC framework like zend?

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?

Errors

HI. I do everything as instructed and get the following error (in the screenshot).
Please help me.
default

Ability to set local variables

<?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
});

php.ini

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.

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.