PHPNodeJS
PHP Node JS wrapper (PHP class that brings executing JavaScript inside PHP - wrapper for NodeJS CLI)
Install / Use
/learn @dincek/PHPNodeJSREADME
PHPNodeJS
PHP Node JS wrapper - PHP class that brings JavaScript executing inside PHP - wrapper for NodeJS CLI.
This class was made that we can use JavaScript based validators of tasks (interacitve tasks) for competition system Bober (programming competition). JavaScript server execution enables us to protect to correct solution for tasks.
We think that this solution could be used for many other things so we published this wrapper online, so you can review it, test it and make it better.
Requirements
- NodeJS (>= v0.10.10, maybe it works with older version (never tested, you are welcome to test and report if it works or not), there must be binary file "node" on server / computer where you execute script)
- If you want to use JavaScript function that uses jQuery you need to install jquery for NodeJS via NPM (in directory where
PHPNodeJS.php is located in your project, you need to run command in CLI:
npm install jquery
Initialize
include_once dirname(__FILE__) . '/PHPNodeJS.php';
// if $debug = true all of debug messages will be shown, otherwise not
$debug = true;
$PHPNodeJS = new PHPNodeJS($debug);
Example 1
Run simple script without function
echo $PHPNodeJS->run('
var var1 = 10;
var var2 = 20;
console.log(var1+var2);
');
Example 2
Run simple script, supply multiple arguments to function you want to call
echo $PHPNodeJS->run('
function test(var1, var2) {
if (var1 == "3" && var2 == "20") {
return true;
} else {
return false;
}
}',
'test', array('3', '20'));
Example 3
Run script that uses jQuery as dependcy
echo $PHPNodeJS->run('
function test(url) {
jQuery.get(url, function(data) {
console.log(data);
});
return "";
}',
'test', array('http://www.videodeck.net'), true);
License
This project is licensed under Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0). You are welcome to contribute to this project or fork this product but we would be very happy that you keep reference to this original project.
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
