IceKickz
11-03-2007, 02:46 PM
Hi there!
I've been deadlocked in some coding (PHP) for a day now and just had to seek out for some more eyes and ears to check if there was anyone who could brainstorm here a little with me... I can't really go into details since it's partly under a NDA.
The problem
Let's use a daily visitors graph as an example... You have a folder with a lot of pictures which shows daily stats, i.eg
Jan01-2007.png, Jan02-2007.png etc etc. I already have a script that generates the information I need to create the picture, but really no routine to update it...
The creation was really just by making a custom 404 redirect from .htaccess (ErrorDocument 404 /myscript.php), so if someone tries to open a picture that doesn't exists, the script creates it. In this example it wouldn't be necessary to update Jan01 after that date, but the generated statistics in the real case will always change...
The problem is having thousands pictures. I don't want to add a php script to the crontab to update them all if they aren't needed. I would want them to be updated everytime someone tries to access that specific picture. I.eg a user goes to somedomain.com/images/Jan01-2007.png. What I wanted to do than was for the script to run a filemtime() (plus i.eg 30 minutes to make it cache it for so long) on the file to get the unix time for the file creation and compare it to the current time(). So if the file was created more than 30 minutes ago, it should recreate it.
Since the script is tied to the 404 error, it would bypass the script when somedomain.com/images/Jan01-2007.png is accessed for the second time; the file exists now, so it should return a 200 http code.
I don't have any problem with the coding part. I've already created all the code for the creation and updating. The problem is redirecting the pictures to the script again when it's accessed. I tried to add ErrorDocument 200 in .htaccess without any luck.
Any suggestions?
I've been deadlocked in some coding (PHP) for a day now and just had to seek out for some more eyes and ears to check if there was anyone who could brainstorm here a little with me... I can't really go into details since it's partly under a NDA.
The problem
Let's use a daily visitors graph as an example... You have a folder with a lot of pictures which shows daily stats, i.eg
Jan01-2007.png, Jan02-2007.png etc etc. I already have a script that generates the information I need to create the picture, but really no routine to update it...
The creation was really just by making a custom 404 redirect from .htaccess (ErrorDocument 404 /myscript.php), so if someone tries to open a picture that doesn't exists, the script creates it. In this example it wouldn't be necessary to update Jan01 after that date, but the generated statistics in the real case will always change...
The problem is having thousands pictures. I don't want to add a php script to the crontab to update them all if they aren't needed. I would want them to be updated everytime someone tries to access that specific picture. I.eg a user goes to somedomain.com/images/Jan01-2007.png. What I wanted to do than was for the script to run a filemtime() (plus i.eg 30 minutes to make it cache it for so long) on the file to get the unix time for the file creation and compare it to the current time(). So if the file was created more than 30 minutes ago, it should recreate it.
Since the script is tied to the 404 error, it would bypass the script when somedomain.com/images/Jan01-2007.png is accessed for the second time; the file exists now, so it should return a 200 http code.
I don't have any problem with the coding part. I've already created all the code for the creation and updating. The problem is redirecting the pictures to the script again when it's accessed. I tried to add ErrorDocument 200 in .htaccess without any luck.
Any suggestions?
