Note: I'm the author of stack.PHP.
You're likely running into rate limitrate limit issues. The API only allows you to make som many requests per second. Quoting from the question I linked to:
The API will cut you off if you make more than 30 requests over 5 seconds to any single endpoint.
Based on past experience, what you need to do is make sure that there is a 100ms delay between requests (I know, that's nowhere near 30/s but there have been issues with that in the past).