-
Notifications
You must be signed in to change notification settings - Fork 14
/
php_worker.php
57 lines (45 loc) · 1.59 KB
/
php_worker.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
54
55
56
57
<?php
/* ======================================================================== *\
Snappy PHP Script Launcher
Pre burner for PHP script execution with note.js
This script initialise various predefined globals in PHP
The STDIN stream/socket contains a JSON encoded array, containing all relevant
data.
This is a close aproximation to the population of globals done by mod_php in Apache
todo:
fake header()
set ini open_basedir
file upload
(c) Copyrights Paragi, Simon Riget 2013
Licence MIT
\* ======================================================================== */
// Prevent that the input socket times out, before it is used
ini_set ("default_socket_timeout","-1" );
// include pre load script
$pre_load_script = getenv('preload');
if(!empty($pre_load_script))
include($pre_load_script);
// Get client request and server information passed throug stdin.
$request=json_decode(file_get_contents("php://stdin"),true);
// Populate predefined global variables, including all http headers
unset($_SERVER,$_REQUEST);
foreach($request as $key => $value)
$$key = $value;
// Clean up
unset($request, $key, $value);
// Set server signature
$_SERVER['SERVER_SIGNATURE'] =
"<address>"
. $_SERVER['SERVER_SOFTWARE']
. ". With " . $_SERVER['GATEWAY_INTERFACE']
. (empty($_SERVER['SERVER_HOST']) ? '' : " at " . $_SERVER['SERVER_HOST'])
. "</address>";
;
// Run script
if(realpath($_SERVER['SCRIPT_FILENAME'])){
chdir(dirname($_SERVER['SCRIPT_FILENAME']));
require $_SERVER['SCRIPT_FILENAME'];
}else{
trigger_error("File $_SERVER[SCRIPT_FILENAME] Missing", E_USER_ERROR);
}
?>