-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
runPython.php
53 lines (42 loc) · 1.22 KB
/
runPython.php
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
43
44
45
46
47
48
49
50
51
52
53
<?php
// Pay Attention for writing Permission for creating files
require_once 'vendor/autoload.php';
// Create new Class
$COMPILER = new eminmuhammadi\phpCompiler();
// Declare variables
// Python mode (other 5 languages support // please read about in source code)
$env = [
'command' => 'python3',
'time' => '5', //seconds
'code' => $_POST['code'] ,
'input' => $_POST['input'],
'fnCode' => 'main.py',
'fnInput' => 'input.txt',
'fnError' => 'error.txt'
];
// Set time for compiler
$time = 1000*$env['time'];
$COMPILER->setTimeOut($time);
// Result Compilation
$RESULT = $COMPILER->Run(
$env['command'],
$env['time'],
false,
false,
$env['code'],
$env['input'],
$env['fnCode'],
$env['fnInput'],
$env['fnError']
);
// Start JSON
header('Content-Type: application/json');
// Join Datas
$data = [
'code' => $env['code'] ,
'time_limit' => $time,
'input' => $env['input'],
'result' => $RESULT
];
// Print Json
echo json_encode($data,JSON_PRETTY_PRINT);