Executing a function on session destruction

I am developing a web user interface that displays some data from a database and displays it to the user. There are literally millions of different graphs that can be generated, so my idea is to dynamically generate the graph, save it to a temporary file, serve the web page, and finally delete the image after a certain period of time.

Thus, I would like to save the paths to already generated images in $ _SESSION so that the files can be deleted when the session is destroyed. Is there a way in PHP to execute a given function (which in this case will be responsible for deleting the above files) when the session is destroyed, when it happens?

+4
source share
1 answer

Yes, see session_set_save_handler , in particular the $destroy and $gc options.

+6
source

Source: https://habr.com/ru/post/1315631/


All Articles