1

I am trying to call a php file from my nodejs file. I have installed and required the exec-php module and it has been install fine. The error I am getting is:

{ Error: Command failed: php C:\Users\***\Desktop\nodejs\xxchat11\node_modules\exec-php\lib\php\cli.php -pC:\Users\***\AppData\Local\Temp\tmp-129647qzlx6s.gh55ewmi.tmp -rC:\Users\***\AppData\Local\Temp\tmp-12964
7pid95t.8vpiizfr.tmp
'php' is not recognized as an internal or external command,
operable program or batch file.
   at ChildProcess.exithandler (child_process.js:204:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:886:16)
    at Socket.<anonymous> (internal/child_process.js:342:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:501:12)
  killed: false,
  code: 1,
  signal: null,
  cmd: 'php C:\\Users\\***\\Desktop\\nodejs\\xxchat11\\node_modules\\exec-php\\lib\\php\\cli.php -pC:\\Users\\***\\AppData\\Local\\Temp\\tmp-129647qzlx6s.gh55ewmi.tmp -rC:\\Users\\***\\AppData\\Local\\Temp\\tmp-
129647pid95t.8vpiizfr.tmp' }

My php file is:

<?php
$hashes = array('md2','md4','md5','sha1','sha224','sha256','sha384','sha512','ripemd128','ripemd160','ripemd256','ripemd320','whirlpool','tiger128,3','tiger160,3','tiger192,3','tiger128,4','tiger160,4','tiger192,4','snefru','snefru256','gost','gost-crypto','adler32','crc32','crc32b','fnv132','fnv1a32','fnv164','fnv1a64','joaat','haval128,3','haval160,3','haval192,3','haval224,3','haval256,3','haval128,4','haval160,4','haval192,4','haval224,4','haval256,4','haval128,5','haval160,5','haval192,5','haval224,5','haval256,5');
function hash($method. $plaintext){
  if(in_array($method, $hashes)){
    $hashed = hash($method, $plaintext);
    echo 'The '.$method.' hash, for the string `'.$plaintext.'` is: '.$hashed;
  } else {
    echo "Method not found! Please type !help to see the list of supported methods.";
  }
}
?>

In my nodejs file I call the php file by:

var execPhp = require('exec-php');

app.get('/hash.php/:method/:text', function(req,res){
  execPhp(__dirname+'/hash.php', function(error, php, output){
    console.log(error);
    //php.hash(req.params.method, req.params.text, function(err, result){
        //res.send(result);
    //});
  });
});

Also, within my index file I am running the app.get() by:

$.get('hash.php/'+method+'/'+plaintext, function(data) {
    $chat.append('Chatbot: <strong>'+data+'</strong><Br />');
});

Have I done anything wrong within this code that will affect the error? Also, If there is a more efficient way of doing this please let me know as I have spent a couple hours already trying to figure out how to get these files to work smoothly.

1 Answer 1

1

exec-php takes 3 parameters:

  1. String. Path to user php file.
  2. String. Path to machine php bin file.
  3. Function. Callback function after creating exec-php object.

You're missing the second parameter, the path to php, that's why you're getting that error.

execPhp(__dirname+'/hash.php', 'PATH_TO_PHP', function //...

To get php location:

Windows:

C:\>where php.exe

Linux

which php

Check this answer: How to determine path to php.exe on windows - search default paths?

Sign up to request clarification or add additional context in comments.

5 Comments

Where would I be able to find the PHP bin folder? I have never seen it.
I think I am having to install it onto my computer, as the where php.exe returns nothing. I will get back to you when I have installed it
You don't have php installed?
I have just downloaded and move it to C:/ but still nothing, php.net/get/php-7.1.4.tar.bz2/from/a/mirror
Ahh, I don't know why but the where php.exe command doesn't work for me. I found it within my xampp folder in c:/. Thank you for helping me :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.