GCM给我随机的Unauthorized 401错误(PHP CURL)

I just implemented my PHP server to send messages over the Google Cloud Messaging Service to my Android device, using CURL.

Everything works fine: I run the script, the message gets sent and successfully received on my mobile device.

Or at least sometimes it does. Sometimes it returns the 401 Unauthorized error. If I run the script 10 times, the error will occour approximately 1-4 times.

The only solution I can come up with right now is putting the whole code into a while($unauthorized) { ... } block, so it will retry sending the message until it gets a HTTP 200 response.

Any other suggestions? Has anyone else experienced this? What could cause this behavior?