I think you are looking for a push notification service.
You can either implement your own (using Comet) or subscribe to a public service.
Examples:
PubNub , BeaconPush
You will find much more with Google.
Edit
I think my answer was not clear enough. With my suggestion you can do this (using pubnub):
User B (user identifier 7) records a user request to user A (user identifier 8). In your PHP handler you do:
$pubnub->publish(array( 'channel' => 'friend_requests_8', 'message' => array( 'request_from' => '7' ) ));
I am not very used to php, but I hope you understand what I mean.
On the "Client" page, you can simply register on your channel ("friend_request_"), and then process the requests:
// PUBNUB.subscribe() - LISTEN PUBNUB.subscribe({ channel : "friend_request_<? echo $user_ID; ?>", callback : function(message) { alert('FRIEND REQUEST FROM USER ID: ' + message.request_from) } })
Thus, with this solution, you do not have to handle any timings or loops, because pubnub handles this for you. Facebook does this (as far as I know), and BeaconPush uses EA for Battlelog, which, in my opinion, is a great website with many interesting web technologies.
source share