My php script parses user’s profile on other site, takes some info and generates .png image with it for certain user (script.php?username=). Each time page with these images is loaded, script runs again and again.
How can I cache images and only run script again if information it outputs was changed? It would save pretty much resources.
My php script parses user’s profile on other site, takes some info and generates
Share
You will need to parse the user’s profile again on each request to find out if something has changed.
You can then throw all the information into some kind of hash like
md5($name.$location)and store this information anywhere. If you now get a request for an image, parse the user’s profile, create the hash again and look this hash up. If you have stored it, you previously created the image and can just output it. If the hash is different, the user’s information has changed, as well and you will have to recreate the image.You can also apply some heuristic like the fact that a user might only change his profile once an hour, or even only once a day. With this assumption you can compare the creation date of the user’s image and only parse the user’s information if the image is older than an hour (or day).