I have a script that creates thumbnails of larger images and it works fine, the problem is that it is placed at the beginning of the page where both images are viewed and to my understanding would run every time someone visits the page. This doesn't seem very performant.
I would rather the script have its own page and somehow detected when more large images had been added to the directory it scans and go to work then.
How would i go about setting this up or improving it in someway?
found this, not sure how it works. what is $cmd:
/*I combined several efforts in this topic into one function:
This will execute $cmd in the background (no cmd window)
without PHP waiting for it to finish, on both Windows and Unix.*/
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
Time base creation : Perhaps (if you have a shell access), you can create a "Cron job" :
In ''/etc/crond.d/'' Create a file like this :
It will be execute every hour from 6.00 to 18.00.
See : http://en.wikipedia.org/wiki/Cron for more details.
Automatic Creation : If you have an "upload procedure", put simply the "Thumbnail generator" after uploading.
Hook Creation : Indeed, it depend of the procedure you use to add new images in your directory.
Perhaps, you can also make a hook to execute the script after updating the dir.
But I think the first solution based on time (cron) is the most easy to implement.