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

View file

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