Reputation: 442
Imagine 2 Applications running with different mysql-databases on the same server. I need a way to exchange data between both applications. One Application has no permission to access the database of the other application. The exchange is only backend related (automatic stuff), no user interaction needed.
What would be the best and safest way to do this using php?
Upvotes: 0
Views: 340
Reputation: 3211
You could use named pipes - they're well suited for interprocess communication.
http://my.opera.com/zomg/blog/2007/08/29/php-and-named-pipes
You can try it out in the interactive php:
Davids-MacBook-Air:~ dearlbry$ php -a
Interactive shell
php > posix_mkfifo("test-pipe", 0644);
php > $pipe = fopen('test-pipe','r+');
php > print fgets($pipe);
Let that sit there waiting, then open another terminal:
Davids-MacBook-Air:~ dearlbry$ php -a
Interactive shell
php > $pipe = fopen('test-pipe','r+');
php > fwrite($pipe, "Hello World\n");
php > fclose($pipe);
Watch the "Hello World" show up in the first process. Make sure you put in the "\n", as pipes are buffered and the newline signals to flush it.
Upvotes: 1
Reputation: 1554
You could use a RESTful API where by one application could POST and GET data to and from the other.
// From application2.com
$id = $curl->post('http://application1.com/users/save/', array(
'name' => 'Matt',
'bio' => 'I am a person.'
));
// $id is generated from a DB insert
$user = $curl->post('http://application1.com/users/bio/', array(
'id' => $id
));
// $user contains an array or object of information about Matt
Upvotes: 0