aboutsummaryrefslogtreecommitdiff
path: root/php/runtime.js
diff options
context:
space:
mode:
authorMinteck <freeziv.ytb@gmail.com>2021-03-07 18:29:17 +0100
committerMinteck <freeziv.ytb@gmail.com>2021-03-07 18:29:17 +0100
commit0f79e708bf07721b73ea41e5d341be08e8ea4dce (patch)
treef3c63cd6a9f4ef0b26f95eec6a031600232e80c8 /php/runtime.js
downloadelectrode-0f79e708bf07721b73ea41e5d341be08e8ea4dce.tar.gz
electrode-0f79e708bf07721b73ea41e5d341be08e8ea4dce.tar.bz2
electrode-0f79e708bf07721b73ea41e5d341be08e8ea4dce.zip
Initial commit
Diffstat (limited to 'php/runtime.js')
-rw-r--r--php/runtime.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/php/runtime.js b/php/runtime.js
new file mode 100644
index 0000000..ce2629d
--- /dev/null
+++ b/php/runtime.js
@@ -0,0 +1,31 @@
+const child = require('child_process');
+const util = require('util');
+const chalk = require('chalk');
+const exec = util.promisify(child.exec);
+
+module.exports = async ([file, id]) => {
+ startd = new Date();
+ try {
+ error = undefined;
+ var { stdout, stderr } = await exec("php \"" + file.split("\"").join("\\\"") + "\"");
+ } catch (e) {
+ error = e;
+ }
+ stopd = new Date();
+ diff = stopd - startd;
+
+ console.log(chalk.gray(cluster.worker.id + " ") + chalk.blueBright("php:") + " total run time: " + diff + "ms");
+
+ returnobj = {error: null, content: null, stderr: null, id: id};
+
+ if (error) {
+ returnobj.error = error;
+ returnobj.stderr = stderr;
+ } else {
+ php.cleanup()
+ returnobj.content = stdout;
+ returnobj.stderr = stderr;
+ }
+
+ return returnobj;
+} \ No newline at end of file