I'm not totally ofay on the authentication bit (I seem to remember something about prepending the URL with the login and password in some way, but that could be something else), but I can help on the timeout.
Before doing anything potentially long-winded, put
set_time_limit($seconds);
The timeout will reset to the value of $seconds whenever this command is reached - i.e., it will run for another $seconds seconds before timing out (longer if the time limit is set again).