But i have them running in crontab every 5 minutes and they sometimes dont close. Can i write something to log why or force them to close after a certain amount of time by killing the pid?
You might be able to use strace to see if they're waiting on a system call of some sort. And php has the function set-time-limit(). As for why it's doing this, I can't tell without seeing the code.