I don't quite follow what problem you are experiencing.
Do you mean that the remote data shows up correctly only after refreshing a few times? If so, the remote server may be slow, and so your php script may be giving up too early.
If so, use set_time_limit() to extend the wait time.