Ajax轮询用户通知

I want to have a server side language that when a new MySQL row is added, notifies only the users that post pertains to. I have a subscribe based system, so I was thinking: When a new MySQL row is added in the posts table, the server side language takes the owner id of that new post, and looks for it in the table that holds the subscribeer data. If a row is found with the post owner's id in the subscribee column, it sends a new notification to the user with the subscriber id in that row... I need help with all of it, server and client side.

Only executing a various queries on an interval for see changes, is not an optimal method.

I recomended other solution like redis. You can create a events channel, and subscribe from a ajax serve, and send evento to the channel from other script.

$redis->subscribe(array('channel1','channel2','channel3'), function ($redis, $chanelname , $msg) {

    echo json_encode(array($chanelname => $msg));
    exit(0);

});

And:

mysql_query('INSERT ....');

$redis->push('chanel1', $data);

learn more about: https://github.com/nicolasff/phpredis