I have made a website for Employers in Laravel 5. Now I want to connect and sync it with a second website on different domain but same server. The 2nd website is for jobseekers which will listen to events for database change by 1st application. For example if a candidate is shortlisted by a employer that corresponding event should be captured and handled in jobseeker application. Please suggest a way to do that, I am not much experienced in Laravel.
You can have the first website make an API call to the second to let it know something has changed. Alternatively, you can have the first website use Laravel's event system in conjunction with the Queue system. Your second application can connect to the database of first application to retrieve and modify its queue.
The API solution provides a bit more flexibility, especially if they were to ever be on separate servers. I would choose whichever you are more comfortable with, it wouldn't take long to implement either if you change your mind later.
Related
I know this subject has been discussed among many in SO but I have a specific issue that I would like to get your opinions on.
I apologize in advance since this is exactly not a coding issue.
I am a self learnt developer and I do not have CS degree exposure or any sort. Majority of everything I know is learnt through the web.
I am planning on developing a multi tenant app which uses angular for front end, laravel for backend/api connecting and mysql to store data.
I plan on assigning a unique key for each tenant identified by 2 or 3 letters (to be decided later) which the user will have to type upon login to identify the tenant. Let's call it the tenantId.
Also, I am contemplating of using a subdomain and getting the subdomain as the tenant id for seperation. Lets assume for this scenario that I have the tenantId with me.
Also, laravel will have 2 connections defined. Lets say tenantconnection(to hold individual tenant db credentials) and masterconnection.
Masterconnection holds db credentials for a database that holds the tenantkey, db username, db password, db name, mysql server address in one of it's tables.
Upon getting the db credentials from mastertenant, laravel will update the tenantconnection initialised in the database.php file in the config folder.
So every API call, laravel will have to connect to master get credentials for tenantconnection and then call the db.
In your opinion/experience how practical/applicable is this?
Can this pose any latency even if the db server and app server is within the same datacenter?
Is this method of connecting an accepted method of connecting in a multi tenant environment?
Also, on every API call to laravel i plan on sending the tenantid through JWT. I am not really comfortable of saving tenantid on localstorage.
Can localstorage be manipulate by using any tools such as firebug or something similar of that nature?
I thought of using sharing the db and using schemas in the same db,but the app is designed to hold financial data so I thought that separating them would be the best. I have researched the pros and cons and decided that using a seperate db for each tenant is the best.
Your feedback is greatly appreciated.
Sorry if posted on the wrong stack site.
Sorry about the long read time.
Most of your questions are opinion-based, which makes it kind of off-topic. I would just add a comment, but it wouldn't fit.
Can this pose any latency even if the db server and app server is within the same datacenter?
I don't think a 10~20ms delay will impose any problems. Make sure you understand the basic of MySQL indexes because if someday you face database problems it is important to not automatically assume it's the tenancy fault. It's usually bad indexes.
Is this method of connecting an accepted method of connecting in a multi tenant environment?
I think so, I'm using it like this. The only difference is that my application is not Web App + API. I use blade.
Also, on every API call to laravel i plan on sending the tenantid through JWT. I am not really comfortable of saving tenantid on localstorage.
I don't know your project specs. If each user can have access to more than 1 tenant, then yes, this seem to be a good approach. If each user BelongsTo a
unique tenant, then why bother with tenant-id at all? Just take the tenant from the user authenticated by the token.
Can localstorage be manipulate by using any tools such as firebug or something similar of that nature?
How to view or edit localStorage
We have an web application built in PHP Laravel, which exposes a bunch of schema objects via JSON API calls. We want to tie changes in our schema to AngularJS in such a way that when the database updates, the AngularJS model (and subsequently the view) also updates, in real-time.
In terms of the database, it can be anything, such as mySQL, SQL Server, etc. There's a couple of ways we're thinking about this:
mySQL commits fire some sort of event at Laravel, which then fires a call to all relevant/listening models/views in AngularJS.
Before any data is changed (edited/added) - Laravel fires an event to AngularJS. In other words, after any successful DB commit, another "thing" is done to notify.
The second seems the obvious, clean way of doing this - since the database is not involved lower down the stack. Is there any better way of doing this?
This question is related:
How to implement automatic view update as soon as there is change in database in AngularJs?
but I don't quite understand the concept of a "room" in the answer.
What (if any) is the best way to efficiently tie database commits (pushing) to the AngularJS view (to render changes)? We want to avoid polling a JSON API for changes every second, of course.
I've also had a similar requirements on one of my projects. We solved it with using node.js and sockjs. Flow is like this:
There is a node.js + SockJS server to which all clients connect.
When db is updated, laravel issues a command to node.js via http (redis also a posibility)
Node.js broadcasts the event to all interested clients (this depends upon your business logic)
Either the client reloads the data required or if message is small enough it can be included in node.js broadcast.
Hope this helps. There is no clean way to do this without using other technologies (node.js / web socket / SSE etc). Much of it depends up on the configuration your clients will be using as well.
I am a PHP developer and the title basically says it all. However I was hoping on some more in-depth information as I am starting to get confused about how the flow for the project I work on should go.
For an (web) application I need to implement a feature like Facebook does it with notifying users about replies/comments and instantly showing these.
I figured I could use long-polling with ajax requests but this does not seem to be a nice solution as the notifications never really are instant and it is resource heavy.
So I should use some form of sockets if I understand correctly, and Node.Js would be a good choice. So based on the last assumption I now get confused about the work flow.
I thought about two possible solutions:
1) It seems to me, that if I would use Node.Js I could skip using PHP at all and base the application on Node.js only.
2) Or I could use PHP as a base and only use Node.js for notifying users and instantly showing messages but saving the data using PHP and Mysql.
These two possibilities confuse me and I can't make up my mind about what would be the "best" and cleanest way.
I do not have much experience in Node.js, played with it for a while. But managing and saving data seems to be hard in Node.js so that is why I came up with option 2.
I know Facebook is build on PHP so I am assuming that they save the data via PHP and notify / instantly show replies and comments via Node.
Could someone help me out on this?
Thanks in advance!
EDIT:
I just noticed, Stackoverflow does something similar. I get a notification in the upper left, and below my question a box with "new answer to this question". I am really interested in the technologie(s) used.
Well you could use node.js for the notifications and PHP for your app.
By googling I found this about real-time-notifications.
You could also just use node.js with socket.io, but this means that you have to learn new technologies as you mention that you have no experience with node.
I haven't used it but you could check this project, for websockets in PHP.
When you have an update that you want to notify users you can use the publish subscriber pattern to notify the intrested in this update.
Take a look in Gearman too.
Personally, I've built a notification system using the pubsub mechanism of redis, with node.js+socket.io. Everytime that there is an update on a record then there is a publish on the appropriate channel. If the channel has listeners then they will be notified. I also store the last 20 notifications in a Redis list.
The appplication is built in PHP. The notification system is built in node.js. They are different applications that see the same data. The communication occurs via redis. For example in the Facebook context:
1) A user updates his status.
2) PHP stores this to the database and Redis
3) Redis knows that this update must publish to the status channel of the specific user and it does.
4) All the friends of the specific user are listening to his status channel (here comes node.js)
5) Node.js pushes the notification in the browser with socket.io
As for facebook, I have read in an article that is using long polling for supporting older browsers. Not sure for this though, needs citation...
AFAIK It would be via two simple methods :
First one that could be very simple is adding a Boolean column to each record that determines if it has been notified or not.
The second method is creating a table to insert all notifications.
However, I'm not sure if there are alternative methods for better performance, But first method is what I do commonly myself. But I think Facebook is using 2nd method, because it has to notify each one to a lot of users.
Your question maybe dublicate of:
Facebook like notifications tracking (DB Design)
Database design to store notifications to users
You could use Server Side Events it involves a bit of JavaScript but nothing overly complicated I think.
The main bulk of this method is PHP though, so you would just use the PHP to query your DB for notifications and SSE will push them to the user.
It does have some limitations though, most notably it's not supported by IE (huge surprise) thought i'd mention it anyway to let you know of other possibilities.
Hope this helps
I have been playing around with Node.js for two days now, I am slowly understanding how it works. I have checked multiple threads and posts now but I seem to either misunderstanding them or the way I am thinking about this application is completely wrong.
My application is mainly based on PHP and uses Node.js as a notifications system.
I first wanted to this solely in Node.js but I am more familiar with PHP so that is why I only want to use Node.js as a notifications system.
I do not have any real code to show as I have been mainly playing around and see all what Node can do and so far it seems to be the thing I need, there is one thing I just can't figure out or seem to mis understand. So far I figured out how to send data between the user and the server and used socket.io for this.
So, what if I have a user, which is registered and logs-in on my application. He then has a socket id from socket.io, but when the user leaves my application and comes back the next day his socket ID is changed because it seems to change on every connection. I need to have my users somehow always have the same socket ID or something else which tells my node.js server that it should only send data to one specific user or multiple users. Also, as the socketid seems to change on every request it is even changed when the user visits a different page so I don't ever seem to know which user is what.
I am a little confused and the flow of working with both PHP and Node.js is still a little mystery to me so I hope my question is clear. I dont want to be depending on many modules as I find all these different modules kind of confusing for a beginner like me.
As long as PHP-Node.js are using sessions stored somewhere else other than flag file sessions let's say a cache service or a database mysql or nosql ..
you can use the "same flat file" sessions thought cache or database could be make your application "more"of course there are additional practises of allowing authenticated users to try to connect by controlling when to render the javascript code that holds the information to connect to socket.io server, where an additional list is stored in memory of all connected having information like username/log/timestamps/session variables/etc..
I am looking at building an external site with a CMS, probably Drupal or ExpressionEngine. The problem is that our company already has a membership database that is designed to work with our existing enterprise software, currently the membership database consists of over 400k rows.
Migrating data from the database manually is not an option as modifications and new data must be accessible in real-time. Because the design of the external database will differ from the CMS's own I have decided the best way forward is to use two databases and force the CMS to use the external to read user information (cannot write to) and a local for everything else the CMS needs to do (read + write).
Is this feasible with these Drupal or ExpressionEngine? Ideally I need to be able to use hooks as I do not wan't to modify core CMS files. Sifting through the docs I am not able to find what I would hook into for ether CMS.
(Note: I know it is possible, but I want to know if it's feasible).
Finally if there is a better way of handling this situation please also chime in. Perhaps there is something at the database level to reference a column in an external database?
I'm clutching at straws someone can point me in the right direction I'm sure.
Edit: Moodle has this functionality built in. Moodle is not suitable to my needs but perhaps their documentation will help you understand my issue better: Moodle - External database authentication
If the data is to remain in an external database, then you probably want to look at creating a web service like an API that allows your external site to access the data. Queries to an external database or notoriously slow.
I'm not a Drupal (D)/ExpressionEnginge (EE) Expert.
For TYPO3 (which I know in depth) (and also for D & EE, I think) you can write your own extension which fetches the user data from your membership database and stores them in the local frontend or backend user table for temp. authentication.
We have build such a thing for a big financial institution even with single sign on and setting the corresponding rights depending on the remote groups.
There are plenty of TYPO3 extensions which can be used as an example.
The other possibility is to avoid again the real time feature and use a synchronization script on database level with checks the membership tables with the D or EE user table in e.g. 5min rhythm.
There is also the option to use a LDAP authentication.
If databases are all MySql then you can create a view which points to the remote membership table you only need to implement the correct columns.
It is always a bad idea to modify the core. ;-)
There's an EE extension for working with external data in MySQL: http://devot-ee.com/add-ons/external-entries . I don't know what db you'll need to access or if this might be made to work with it, though.
In ExpressionEngine there are six tables that contain Member and Member Group data (EE's lingo for users/user groups).
exp_members
exp_member_groups
exp_member_bulletin_board
exp_member_data
exp_member_fields
exp_member_homepage
In all likelihood you'd need to sync your user database with exp_members and exp_member_groups at a regular interval to make this happen. Trying to have EE connect to the external DB will likely get you in trouble fast.
If you are simply wanting access to your external database, you can write plugins that connect behind the scenes and make your data available inside your templates.
I worked a a Rails app once that pushed the Rails users to become EE members and shared sessions between them so users could view both systems and stay logged in.