From 57d88558cc516a819e457be4c093d19a6c703216 Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Fri, 10 Jul 2015 17:19:53 +0200 Subject: [PATCH] [add] another method for manualy generate thumb on error --- bin/rasterize.js | 4 ++-- bin/thumb_server.sh | 23 +++++++++++------------ inc/admin.php | 39 +++++++++++++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/bin/rasterize.js b/bin/rasterize.js index 50bbf74..eb7de8a 100644 --- a/bin/rasterize.js +++ b/bin/rasterize.js @@ -8,7 +8,7 @@ if (phantom.args.length < 2) { address = phantom.args[0]; output = phantom.args[1]; page.settings.userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0'; - page.viewportSize = { width: 1280, height:1024}; + page.viewportSize = { width: 1280, height:1024}; page.open(address, function (status) { if (status !== 'success') { @@ -20,7 +20,7 @@ if (phantom.args.length < 2) { page.render(output); page.close(); phantom.exit(); - }, 300); + }, 1000); } }); } diff --git a/bin/thumb_server.sh b/bin/thumb_server.sh index 07cff1f..5c1f6f5 100755 --- a/bin/thumb_server.sh +++ b/bin/thumb_server.sh @@ -16,7 +16,7 @@ waitForResult=$6 # if true we try to make soon as possible or add to queue ##### for overwrite options ##### ########################################## maxThread=1 # max parralle work. For me the best is nb core - 1 -timeOut=60 # default time out, after this time the site are declared in error +timeOut=190 # default time out, after this time the site are declared in error log=false # log all generation success and error randomSleep=`echo $((RANDOM%20))` optimizeTool='' # external tool form optimize png @@ -27,7 +27,7 @@ secondLevel=${hashUrl:2:2} startPath=$sizeNameDir/$firstLevel/$secondLevel/ getArch=$(getconf LONG_BIT) #echo $getArch -if [ $site == "manual" ] +if [ "$site" -eq "manual" ] then site=$(cat "../cache/tmp/manual.txt") echo '' > "../cache/tmp/manual.txt" @@ -57,26 +57,26 @@ fi start_time=`date +%s` if [ $getArch -eq 64 ] then - timeout $timeOut ./phantomjs_x64 --disk-cache=false --local-storage-path=bin/ --ignore-ssl-errors=true rasterize.js "$site" "../cache/tmp/$hashUrl.png" + phanTom=$(./phantomjs_x64 --disk-cache=false --local-storage-path=../cache/tmp --ignore-ssl-errors=true --web-security=false rasterize.js "$site" "../cache/tmp/$hashUrl.png") else - timeout $timeOut ./phantomjs_x86 --disk-cache=false --local-storage-path=bin/ --ignore-ssl-errors=true rasterize.js "$site" "../cache/tmp/$hashUrl.png" + phanTom=$(./phantomjs_x86 --disk-cache=false --local-storage-path=../cache/tmp --ignore-ssl-errors=true --web-security=false rasterize.js "$site" "../cache/tmp/$hashUrl.png") fi -sleep 5 - if [ ! -f "../cache/tmp/$hashUrl.png" ] then echo 0 - errorCode=`echo $(curl -k --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)` + errorCode=`echo $(curl -k -L --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)` + echo $site if [ $site == 'manual' ] then errorCode='manual' fi + echo $errorCode case $errorCode in - 000) cp "../bin/000.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "../bin/000.png" "../cache/img/$startPath""$hashUrl.png" && cp "../bin/000.png" "../cache/img/$startPath""$hashUrl""_complete.png";; - 200) 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";; - 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";; + 000) cp "000.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "000.png" "../cache/img/$startPath""$hashUrl.png" && cp "000.png" "../cache/img/$startPath""$hashUrl""_complete.png";; + 200) cp "error.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "error.png" "../cache/img/$startPath""$hashUrl.png" && cp "error.png" "../cache/img/$startPath""$hashUrl""_complete.png";; + 404) cp "404.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "404.png" "../cache/img/$startPath""$hashUrl.png" && cp "404.png" "../cache/img/$startPath""$hashUrl""_complete.png";; + *) cp "error.png" "../cache/img/$startPath""$hashUrl""_thumb.png" && cp "error.png" "../cache/img/$startPath""$hashUrl.png" && cp "error.png" "../cache/img/$startPath""$hashUrl""_complete.png";; esac rm "../cache/tmp/$hashUrl.lock" if $log @@ -93,7 +93,6 @@ then exit fi - case $renderType in # thumbnail only t) diff --git a/inc/admin.php b/inc/admin.php index 55b8511..b123ef2 100644 --- a/inc/admin.php +++ b/inc/admin.php @@ -125,6 +125,31 @@ function keepThisThumb($hash, $log) { unlink('cache/logs/'.$log.'/'.$hash.'.log'); } +function tryWithCurl($hash, $log) { + $line = file_get_contents('cache/logs/'.$log.'/'.$hash.'.log'); + $line = trim($line); + $line = explode(' --- ', $line); + //$hash = sha1($GLOBALS['config']['salt'].rawurldecode($line[1])); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $line[1]); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_USERAGENT, 'SoShot - perSOnal thumbSHOTer'); + $resultat = curl_exec($ch); + curl_close($ch); + file_put_contents('cache/tmp/'.$line[2].'.html', $resultat); + chdir('bin/'); + exec('bash thumb_server.sh ../cache/tmp/'.$hash.'.html '.escapeshellarg($line[2]).' '.escapeshellarg($line[3]).' '.escapeshellarg($line[4]).' trc 1', $result); + chdir('../'); + //unlink('../cache/tmp/'.$hash.'.html'); + if ((int)$result[0] == 1) { + $res['success'] = 1; + $res['filePath'] = pathForFile($line[4], $hash).'.png'; + $res['base64'] = 'data:image/png;base64,'.base64_encode(file_get_contents($res['filePath'])); + return $res; + } +} + if (isset($ui['clear']) && (int)$ui['clear'] === 1) { clearLog($ui['log']); } @@ -204,7 +229,7 @@ if (isset($ui['log']) && $ui['log'] === 'success') { $nbThumb = 0; $nbThumb = count($logs['genTime']); echo 'Total request : ', $nbThumb, '
'; - echo 'Moyenne per request : ', round(array_sum($logs['genTime']) / $nbThumb, 2), 's (min (', min($logs['genTime']), 's) max (', max($logs['genTime']), 's))
'; + echo 'Moyenne per request : ', round(array_sum($logs['genTime']) / $nbThumb, 2), 's (min (', min($logs['genTime']), 's) max (', max($logs['genTime']), 's))
'; } else { echo 'No result'; } @@ -212,7 +237,7 @@ if (isset($ui['log']) && $ui['log'] === 'success') { } if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || $ui['log'] === 'other')) { if (isset($ui['hash']) && !empty($ui['hash'])) { - $ui['hash'] = validHash($ui['hash']); + //$ui['hash'] = validHash($ui['hash']); if (isset($ui['root']) && (int)$ui['root'] === 1) { $success = tryRootDomain($ui['hash'], $ui['log']); } @@ -229,12 +254,15 @@ if (isset($ui['log']) && ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || if (isset($ui['mGen']) && (int)$ui['mGen'] === 1) { $success = manualGen($ui['hash'], $ui['log']); } + if (isset($ui['tryCurl']) && (int)$ui['tryCurl'] === 1) { + $success = tryWithCurl($ui['hash'], $ui['log']); + } } $logs = parseFailLog($ui['log']); if (!empty($logs)) { echo ''; } else { @@ -246,7 +274,10 @@ if (!empty($success)) { echo '
'; echo ''; echo '

'; - echo 'manuel launch / '; + echo 'Manuel launch / '; + if (extension_loaded("curl")) { + echo 'Try with curl / '; + } echo 'Try with root domain / '; echo 'Keep this thumbshot'; echo '
';