We are having a very strange and hard-to-diagnose problem with a rather simple scheduled task. On Windows Server 2008, we run a PHP script once per minute using VC "exec". The PHP script loads a COM object that provides an IMAP client, which the script uses to check for new mail on the mail server. The operation takes a second or less and runs fine several thousand times. Then, for no apparent reason, it just stops working. The specific error returned is 10022 (a Winsock error that is defined only as "invalid argument"--extensive web searches turned up nothing useful). What's even stranger is that I can open a command-prompt and run the same script successfully, even as the VC-scheduled version continues to fail. So far, rebooting the server is the only fix (I've tried restarting VC).
I've been through just about everything I can think of, including:
+ running the VC service and the script as SYSTEM
+ running the VC service as the local Administrator
+ running the VC service as SYSTEM and having VC use Administrator credentials
None of this makes any difference (and it's not that the script requires Administrator rights--for the several thousand times it works, it can happily run as SYSTEM).
To try to diagnose the problem, I've looked for memory leaks, port leaks, system log events, details of some other external event that happens just before the failures start, etc. So far, nothing at all has come up.
An interesting side-effect is that another completely unrelated COM object on the server also fails once the failures start (but this one runs infrequently, and is clearly not the triggering event of the failures). At first, this made me think that the problem with COM related, but other COM objects on the server work fine. My only theory is that the problem is at the level of the Winsock and/or TCP/IP, and that the unrelated failing COM object is somehow doing a TCP call when it tries to start up (I have no knowledge of what it does internally).
So...what I'm looking for is some thoughts on how I might go about diagnosing this. One question that immediately comes to mind is why I would be able to run the PHP script from a command-prompt, even while the VC-scheduled one is failing?
Any ideas would be greatly appreciated!