Yes, sure you can do it with PHP.
What you need to do is to have a field called "lastaction" which store the last UNIX time stamp that the user has been used the site. This field should be updated every time the user do any activities on the site.
Then do the calculation between the current time stamp (use time() function) and the lastaction value. If the time difference (in seconds) is greater than the timeout value you configured, you should clear all the cookies and delete any sessions and this should log the current user out.