aboutsummaryrefslogtreecommitdiff
path: root/php/runtime.js
blob: fc0c122960043c43e5a106823af61fb47a4a3761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const child = require('child_process');
const util = require('util');
const chalk = require('chalk');
const fs = require('fs');
const exec = util.promisify(child.exec);

module.exports = async ([file, id]) => {
    startd = new Date();
    try {
        error = undefined;
        if (require('os').platform() === "win32") {
            var { stdout, stderr } = await exec("runtime\\php.exe \"" + file.split("\"").join("\\\"") + "\"");
        } else {
            var { stdout, stderr } = await exec("php \"" + file.split("\"").join("\\\"") + "\"");
        }
    } catch (e) {
        error = e;
    }
    stopd = new Date();
    diff = stopd - startd;

    if (fs.existsSync(file + ".ELECTRODECACHE~.php")) {
        fs.unlinkSync(file + ".ELECTRODECACHE~.php");
    }

    require('../core/cacheClean')();

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