How to run a Node.js script from PHP with XAMPP?
<p>I am using XAMPP on Windows 7 to run a localhost, and I'm trying to use the PHP <code>exec</code> function to execute a Node.js script.</p>

<p>I am able to successfully use the <code>exec</code> function to run PhantomJS scripts, but when I try to do the same thing for Node.js, it doesn't work.</p>

<p>He's an example of a PHP script that properly runs a PhantomJS script:</p>

<pre><code>&lt;?php

  exec('/phantomjs/bin/phantomjs /phantomjs/scripts/test.js', $output);
  print_r($output);
</code></pre>

<p>And here's a similar example of a Node.js script that outputs an empty array every time:</p>

<pre><code>&lt;?php

  exec('/Program Files (x86)/nodejs/node /Program Files (x86)/nodejs/test.js', $output);
  print_r($output);
</code></pre>

<p>I'm sure that all of my paths are correct and that the Node.js script executes correctly whenever I execute it directly from the command line, but I can't get anything to return from the Node.js script when I run it from the PHP <code>exec</code> command. I also tried the following script, but I still get nothing:</p>

<pre><code>&lt;?php

  exec('/Program Files (x86)/nodejs/node -v', $output);
  print_r($output);
</code></pre>

<p>Any advice on what I'm missing would be greatly appreciated. Thank you.</p>