2

I would like to implement a real time notification like facebook on my website using angular, php and mysql. Is there any reference links or tutorials anyone can help me out with?

Also, is there any other tools by which I can implement the same on my website?

2
  • 3
    You should have googled before asking such questions..CommentedMay 20, 2016 at 5:11
  • 2
    There's no simple answer to this. You'll want to research "long polling" or if you are feeling adventurous a library such as socket.io
    – John
    CommentedMay 20, 2016 at 5:12

2 Answers 2

3

Try to use Socket.io, it will help you to implement notification , chat or any real time application.

1
  • 1
    any tutorial you can suggest using it with PHP? Also, is there any support issues on browser like internet explorer?
    – akhil
    CommentedMay 20, 2016 at 6:06
2

You can use these things to make such functionalities.

  1. PHP JSON Based API
  2. PHP Socket Based JSON API
  3. Socket IO based API

All these API can easily be parsed by AngularJS or jQuery

For PHP, How to make an API

<?php //Set header for Javascript to recognize it as the JSON output header('Content-Type:application/json;'); //I am using GET parameters, but POST can also be used and can make amazing APIs switch($_GET['action']){ case "addlike": //SQL Query passed to add a like as facebook //Set the output array to provide json Output, here's the example $output['status'] = 200; $output['message'] = 'Like Added'; break; case "addcomment": break; } echo json_encode($output); 

To use above code, the URL would be:

http://yourserve/youfile.php/?action=addlike 

And the Output would be

{ "status":200, "message":"Like Added" } 

How to use it in jQuery

/** For Example you have like button with class="btnlike" **/ $('.btnlike').on('click',function(){ $.get('http://yourserve/youfile.php',{action:'addlike'},function(data){ if(data['status'] == 200){ alert('You Liked the Post'); } }); }); 

How to use in AngularJS

app.controller('myCtrl',function($scope,$http){ $scope.message = ''; $scope.addlike = function(){ $http.get('http://yourserve/youfile.php',{action:"addlike"}).success(function(data){ if(data['status']==200){ $scope.messages = 'You liked the post'; } }); }; }); 
11
  • 2
    this was really helpful Marmik, can you please help me out with implementing this on a thing like showing notification after a cron job execution. for eg, consider a cron job executing every 5 minutes and update some data to mysql table. I have to show a real time notification after that. How can I acheive this with angular? since I have no event like a button click, how can I invoke angular code??
    – akhil
    CommentedMay 20, 2016 at 5:55
  • 2
    any performance issues with this? How about a high traffic website? Any issues performing an AJAX request every second?
    – akhil
    CommentedMay 20, 2016 at 6:05
  • 2
    It is kind of a social network and current case is like you have commented on my photo and I have to get the notification
    – akhil
    CommentedMay 20, 2016 at 6:41
  • 2
    Am afraid I cannot change the framework. Is there any way to implement this zf2 and node js or something like @Meesam mentioned. But am really confused with implementing it on a shared server as I will be initially running on it.
    – akhil
    CommentedMay 20, 2016 at 6:47
  • 1
    so you suggest socket.io with nodejs?
    – akhil
    CommentedMay 20, 2016 at 6:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.