Skip to content

thespielplatz/PHP-NodeJS-Executor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP-NodeJS-Executor

by #thespielplatz

MIT License Badge

A small, simple PHP class for executing Node.js files.

Problem

In certain scenarios, you may need to execute a Node.js script from a PHP environment. While it's common to have a Node.js server running, setting one up might require significant effort. This class offers a straightforward solution.

What It Does

  • Verifies if PHP can execute Node.js and stores the version.
  • Executes a script, returning the output and the exit code. (Refer to Node.js Process Exit Codes for details.)

Example Usage

require 'NodeJSExecutor.php';

$executor = new NodeJSExecutor();
$executor->run("test.js");

echo "Exit Code: " . $executor->exitCode . "<br>";
echo "Result: " . $executor->result . "<br>";

Exceptions

The class can trigger two exceptions:

  • Node.js is not found (checks the result of node --version).
  • The specified JavaScript file is not found.

Tip me

If you appreciate this project, feel free to use it, refactor it, enjoy it, or even expand on it. Why not send some tip love?

About

Small Simple PHP Class for executing Node Js Files

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
license-badge.svg

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages