[add] lock for prevent multi generation of same url

This commit is contained in:
Knah Tsaeb 2015-07-10 13:09:15 +02:00
parent 79457ee9c3
commit 5d4edab2a4
2 changed files with 4 additions and 2 deletions

View file

@ -78,6 +78,7 @@ then
404) cp "../bin/404.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "../bin/404.png" "../cache/img/$startPath""$hashUrl.png" && cp "../bin/404.png" "../cache/img/$startPath""$hashUrl""_complete.png";; 404) cp "../bin/404.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "../bin/404.png" "../cache/img/$startPath""$hashUrl.png" && cp "../bin/404.png" "../cache/img/$startPath""$hashUrl""_complete.png";;
*) cp "..bin/error.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "../bin/error.png" "../cache/img/$startPath""$hashUrl.png" && cp "../bin/error.png" "../cache/img/$startPath""$hashUrl""_complete.png";; *) cp "..bin/error.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "../bin/error.png" "../cache/img/$startPath""$hashUrl.png" && cp "../bin/error.png" "../cache/img/$startPath""$hashUrl""_complete.png";;
esac esac
rm "../cache/tmp/$hashUrl.lock"
if $log if $log
then then
end_time=`date +%s` end_time=`date +%s`

View file

@ -138,6 +138,7 @@ function testExistImg($file) {
* @return * @return
*/ */
function launchScript($url, $hashUrl, $width, $size, $waitForResult = false) { function launchScript($url, $hashUrl, $width, $size, $waitForResult = false) {
$oriUrl = $hashUrl;
$hashUrl = escapeshellarg($hashUrl); $hashUrl = escapeshellarg($hashUrl);
$url = escapeshellarg($url); $url = escapeshellarg($url);
$width = escapeshellarg($width); $width = escapeshellarg($width);
@ -151,8 +152,8 @@ function launchScript($url, $hashUrl, $width, $size, $waitForResult = false) {
$renderType = 't'; $renderType = 't';
} }
if ($GLOBALS['config']['disableExec'] === false) { if ($GLOBALS['config']['disableExec'] === false) {
if (!file_exists('../cache/tmp/'.$hashUrl.'.lock')) { if (!file_exists('cache/tmp/'.$hashUrl.'.lock')) {
touch('../cache/tmp/'.$hashUrl.'.lock'); touch('cache/tmp/'.$oriUrl.'.lock');
chdir('bin/'); chdir('bin/');
if ($waitForResult === false) { if ($waitForResult === false) {
exec('bash thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$renderType.' > /dev/null &', $result); exec('bash thumb_server.sh '.$url.' '.$hashUrl.' '.$width.' '.$size.' '.$renderType.' > /dev/null &', $result);