tags:

views:

272

answers:

1

Hi guys, I've built a php script that runs from the command line. It opens a connection into a pop3 email account and downloads all the emails and writes them to a database, and deletes them once downloaded. I have this script being called from the commandline by a bat file. in turn I have created a scheduled task which invokes the bat file every 5 minutes. The thing is that I have set the time out to zero for the fact that at times there could be emails with large attachments and the script actually downloads the attachments and stores them as raw files offline and the no timeout is so that the script doesnt die out during downloading.

I've found that the program hangs sometimes and its a bit annoying at that - it always hangs are one point i.e. when negotiating the connection and getting connected to the mail server. And because the timeout is set to zero it seems to stay stuck up in taht position. And because of that the task is not run as its technically hung up.

I want that the program should not timeout when downloading emails - however at the points where it is negotiating a connection or trying to connect to the mailserver there should be a timeout only at that point itself and not the rest of the program execution.

How do I do this :(

A: 

The timeout value can be set using socket_set_timeout() if you're using sockets directly. You can have a look at this other question for details. If you're using a library, you should check its docs. But I would rather check if it really is the timeout issue. Log php errors into a file and you can browse them all. Set the max_execution_time to some acceptable value (like 10 minutes) and check the logs when it hangs again, if it's always the same line where it's failing.

soulmerge