[add] lock for prevent multi generation of same url

This commit is contained in:
Knah Tsaeb 2015-07-10 12:09:20 +02:00
parent d45aa32900
commit 79457ee9c3
2 changed files with 19 additions and 10 deletions

View file

@ -109,6 +109,7 @@ case $renderType in
echo 0
fi
rm "../cache/tmp/$hashUrl.png"
rm "../cache/tmp/$hashUrl.lock"
;;
# thumbnail + complete
tc)
@ -125,6 +126,7 @@ case $renderType in
else
echo 0
fi
rm "../cache/tmp/$hashUrl.lock"
;;
# thumbnail + realsize
tr)
@ -142,6 +144,7 @@ case $renderType in
else
echo 0
fi
rm "../cache/tmp/$hashUrl.lock"
;;
# thumbnail + realsize + complete
trc)
@ -161,7 +164,8 @@ case $renderType in
else
echo 0
fi
rm "../cache/tmp/$hashUrl.png"
rm "../cache/tmp/$hashUrl.png"
rm "../cache/tmp/$hashUrl.lock"
;;
esac

View file

@ -151,13 +151,18 @@ function launchScript($url, $hashUrl, $width, $size, $waitForResult = false) {
$renderType = 't';
}
if ($GLOBALS['config']['disableExec'] === false) {
chdir('bin/');
if ($waitForResult === false) {
exec('bash thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$renderType.' > /dev/null &', $result);
if (!file_exists('../cache/tmp/'.$hashUrl.'.lock')) {
touch('../cache/tmp/'.$hashUrl.'.lock');
chdir('bin/');
if ($waitForResult === false) {
exec('bash thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$renderType.' > /dev/null &', $result);
} else {
exec('bash thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$renderType.' 1', $result);
}
chdir('../');
} else {
exec('bash thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$renderType.' 1', $result);
return 0;
}
chdir('../');
} else {
makeQueueFile($url, $hashUrl, $width, $size, $renderType);
$result = 0;
@ -328,7 +333,7 @@ function removeOlderThan($dir = 'cache/img/shortLive') {
function pathForFile($size, $hashUrl) {
$startPath = substr($hashUrl, 0, 2).'/'.substr($hashUrl, 2, 2).'/';
if(empty($size)){
if (empty($size)) {
$size = tryDetectSize($startPath.$hashUrl);
}
$file = 'cache/img/'.$size.'/'.$startPath.$hashUrl;
@ -412,9 +417,9 @@ function n_print($data, $name = '') {
echo '<h2>', $name, '</h2>';
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">
', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '
', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '
</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '
</fieldset>
<br />
@ -635,7 +640,7 @@ if (!empty($ui['request']) && $ui['p'] !== 'install' && $ui['p'] !== 'login' &&
</head>
<body>
<?php
require getPage($ui['p']);
require getPage($ui['p']);
?>
</body>
</html>