0

I'm creating a network of websites that should communicate between themselves, for example to let all of them display an article published on one of them, or display data stored in a database of another subdomain, etc...

And this all using ajax for interactivity.

Which could be the best (and simplest) way to achieve this?

I thought an ajax call could summon a php script that could call another script on another subdomain. Is it the right way?

Thanks

Bakaburg
  • 3,165
  • 4
  • 32
  • 64
  • Are all the sites hosted on the same server with the same database? Do you have root access to them all? – demux Feb 21 '11 at 16:09
  • 2
    If you're only interested in sharing articles, why not just connect directly to the databases you're interested in via php? Using javascript just adds an unnecessary communication cycle – Sam Dufel Feb 21 '11 at 16:09
  • @Arnar: Yes I have access to all of them – Bakaburg Feb 21 '11 at 17:13
  • @Sam: because I have many databases for each of these domains. I prefer to communicate with the site and let it manage is own database connection. – Bakaburg Feb 21 '11 at 17:15

1 Answers1

1

I don't know exactly what you want to do. If you control the sites and server you could save all your users a lot of ajax calls if you skip doing it that way and do it on the server itself.

If you display all the articles by using javascript, users without javascript won't see anything and search engines won't be able to crawl the website.. however, maybe that's what you want.

The correct design pattern for something like this is to implement a restful API that all the other sites read from..

So you have a central API on eg. http://api.example.com/

and when a server wants to display an article, he would do something on the back end to retrieve an article list.. eg.

http://api.example.com/retrieveNewestArticles

that would return eg. a json variable with a list of the newest article.. then when you want to display that article, you would call:

http://api.example.com/showArticle/58484

That's how I would do it at least.

Some people might suggest doing it by making all the websites connect directly to the same database. That's an option, a bit more messy in the long run, but will get the job done.

certainly easier than my suggestion.

arnorhs
  • 10,383
  • 2
  • 35
  • 38
  • So you suggest to create a domain to manage all the connections? Than I need a script on every subdomain to be call from the central service to retrieve the data. Maybe another solution is to save the data to a repository (database or, other suggestions?) in the backend so that are the domains themselves to send the data. – Bakaburg Feb 21 '11 at 17:25
  • @Arnar - fokking snillingur :) @bakaburg - that's one way. If you're going to be managing the same instance of some code in multiple places, some version control would be in order. Most of them support special post-back hooks, so when you update the central repository, you could make all the code everywhere get updated.. but if the websites you're thinking about will be using 100% of the same code, you could also set it up so it's just using a single framework, but you make that single framework handle all the domains – arnorhs Feb 21 '11 at 21:19
  • And using something like Django is a good idea, but Django is of course a python framework. I can recommend Kohana :) – arnorhs Feb 21 '11 at 21:21