Skip to content

Commit bb3c4ea

Browse files
committed
melody sfProcess timeouts are now configurable via config.php
1 parent fcee19d commit bb3c4ea

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

config.php.dist

+3
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ return array(
1212
// the code entered by the user is evaluated. any variables and classes
1313
// defined here will be accessible by the eval'd code
1414
'bootstrap' => null,
15+
16+
// maximun execution time for melody scripts
17+
'melody-timeout' => 600,
1518
);

index.php

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// the code entered by the user is evaluated. any variables and classes
1313
// defined here will be accessible by the eval'd code
1414
'bootstrap' => null,
15+
16+
// maximun execution time for melody scripts
17+
'melody-timeout' => 60,
1518
);
1619

1720
if (file_exists(__DIR__.'/config.php')) {
@@ -88,6 +91,7 @@ function runCode($__source_code, $__bootstrap_file)
8891
$start = microtime(true);
8992

9093
$melodyPlugin = new MelodyPlugin();
94+
$melodyPlugin->setTimeout($options['melody-timeout']);
9195
if ($melodyPlugin->isMelodyScript($code)) {
9296
if ($melodyPlugin->isScriptingSupported()) {
9397
// make sure krumo class is available in the melody script

lib/MelodyPlugin.php

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* @see https://github.com/sensiolabs/melody
1515
*/
1616
class MelodyPlugin {
17+
private $timeout = 60;
18+
1719
public function isMelodyScript($source) {
1820
return preg_match(ResourceParser::MELODY_PATTERN, $source);
1921
}
@@ -47,6 +49,7 @@ public function runScript($__source_code, $__bootstrap_file)
4749
// we only have one output channel to the browser, just echo "all the things"
4850
echo $text;
4951
};
52+
$process->setTimeout($this->timeout);
5053
$process->run($callback);
5154
};
5255

@@ -64,4 +67,8 @@ public function runScript($__source_code, $__bootstrap_file)
6467
file_put_contents($tmpFile, $__source_code);
6568
$melody->run($tmpFile, array(), $runConfiguration, $userConfiguration, $executor);
6669
}
70+
71+
public function setTimeout($timeout) {
72+
$this->timeout = $timeout;
73+
}
6774
}

0 commit comments

Comments
 (0)