2017-05-01 2 views
1

J'essaie d'appeler un fichier php depuis mon fichier nodejs. J'ai installé et requis le module exec-php et il a été installé correctement. L'erreur que je reçois est:Module exec-php NodeJs, php n'est pas une commande

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

Mon fichier php est:

<?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."; 
    } 
} 
?> 

Dans mon dossier nodejs j'appelle le fichier php par:

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

De plus, dans mon dossier index Je cours le app.get() par:

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

Ai-je fait quelque chose de mal dans ce code qui affectera l'erreur? Aussi, s'il y a un moyen plus efficace de le faire, faites le moi savoir car j'ai déjà passé quelques heures à essayer de trouver comment faire fonctionner ces fichiers correctement.

Répondre

1

exec-php prend 3 paramètres:

  1. String. Chemin d'accès au fichier php de l'utilisateur.
  2. String. Chemin d'accès à la création du fichier bin php.
  3. Function. Fonction de rappel après la création de l'objet exec-php.

Il vous manque le deuxième paramètre, le chemin vers PHP, c'est pourquoi vous obtenez cette erreur.

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

Pour obtenir l'emplacement php:

Fenêtres:

C:\>where php.exe 

Linux

which php 

Cocher cette réponse: How to determine path to php.exe on windows - search default paths?

+0

Où pourrais-je trouver le dossier bin de PHP? Je ne l'ai jamais vu. –

+0

Vérifiez ma mise à jour anser! –

+0

Je pense que je dois l'installer sur mon ordinateur, car l'endroit où php.exe ne renvoie rien. Je reviendrai à vous quand je l'aurai installé –