Sunday, June 8, 2014

How to clear php session files via ssh

My linux vps was giving problem and I found it’s because php was saving all the session files and now thousands of session files were causing the trouble.
To get it fixed I needed to remove/delete the session files.

To remove session files first I located the path where php is saving session files using this command
php -r 'echo session_save_path(), "\n";'

When I tried to remove the files by using the usual file/directory removing command
$ rm –r /session-path/*

It gave me following error
bash: /bin/rm: Argument list too long

After some googling I found this command that worked for me
$ rm -r /session-path/

Nothing special in this command just ‘*’ is not typed in the end but it does the trick.
It deletes the directory and all the saved session files.

Remember to recreate the directory or you will have login errors.
To do that use this command:
$ mkdir /session-path/

I hope it help.

No comments:

Post a Comment