Skip to content

Instantly share code, notes, and snippets.

@milo
Created January 18, 2013 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milo/4567608 to your computer and use it in GitHub Desktop.
Save milo/4567608 to your computer and use it in GitHub Desktop.
Nette #930 issue stress code
<?php
use Nette\Diagnostics\Debugger, Nette\Caching\Cache;
require '/home/milo/dev/nette/Nette/loader.php';
set_time_limit(0);
define('TEMP_DIR', __DIR__ . '/temp');
define('LOG_DIR', __DIR__ . '/log');
define('CHILDREN', 10);
define('LOOPS', 1000);
Nette\Diagnostics\Debugger::enable(FALSE, LOG_DIR);
Nette\Diagnostics\Debugger::$strictMode = TRUE;
Nette\Diagnostics\Debugger::$showLocation = TRUE;
$journal = new Nette\Caching\Storages\FileJournal(TEMP_DIR);
$storage = new Nette\Caching\Storages\FileStorage(TEMP_DIR, $journal);
$cache = new Cache($storage);
// I'm the parent, children's manager
if (!in_array('child', $_SERVER['argv'])) {
$processes = array();
$finished = array();
echo "Queue:\n";
for ($i = 0; $i < CHILDREN; $i++) { // start children
$cmd = 'php ' . escapeshellarg(__FILE__) . ' child';
$descriptors = array(
array('pipe', 'r'),
array('pipe', 'w'),
array('pipe', 'w'),
);
$pipes = array();
$fd = proc_open($cmd, $descriptors, $pipes, __DIR__, NULL, array('bypass_shell' => TRUE));
list($stdin, $stdout, $stderr) = $pipes;
fclose($stdin);
$processes[$i] = (object) array(
'fd' => $fd,
'stdout' => $stdout,
);
echo '.';
}
echo "\n\nWaiting:\n";
while (count($processes)) {
foreach ($processes as $i => $process) {
$status = proc_get_status($process->fd);
$tmpCode = $status['exitcode'];
if (!$status['running']) {
$output = stream_get_contents($process->stdout);
$code = proc_close($process->fd);
$finished[$i] = (object) array(
'exitCode' => $code === -1 ? $tmpCode : $code,
'output' => $output,
);
unset($processes[$i]);
echo '.';
}
}
usleep(1000);
}
echo "\n\nResult:\n";
foreach ($finished as $i => $data) {
if ($data->exitCode !== 0) {
echo "FAILED $i:\n";
echo $data->output . "\n";
echo str_repeat('-', 80) . "\n\n";
}
}
exit(0);
}
// I'm a child, the cache writer
for ($i = 0; $i < LOOPS; $i++) {
$flags = array(
Cache::TAGS => array('tag'),
);
$cache->save('key', array(), $flags);
$cache->clean($flags);
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment