/    Sign up×
Community /Pin to ProfileBookmark

PHP RMI capabilities?

Is this possible? I’ve done a project in Java involving data (XML) being shared between distributed systems syncronously using RMI, but I was wondering if it’s possible to do this using PHP?

What I’m trying to achieve is a syncronous connection to an object which will have many clients connected to it (different people) and they can all share the same data syncronously.

AJAX can do this this, but it’s always interacting with the database. I don’t want to interact with a database–is there some way to keep a PHP object alive to receive and release data syncronously to clients (users on the system).

Ultimately, I want to make it so that every client connects to a “live” PHP object, and then that PHP object connects to the database. Kind of like a manager class in a typical RMI system.

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@chazzySep 15.2006 — PHP has shared memory capabilities http://php.net/shmop

It's inherently faster than java since RMI requires serialization to pass between the VM's but since java is faster than PHP, it's a toss up.
Copy linkTweet thisAlerts:
@BuezaWebDevauthorSep 16.2006 — That was an interesting read, since I didn't even know about the shared memory functions--but I was wondering if there was a way to keep a PHP object alive to receive and release data syncronously... When a person loads the page, an object is instantiated...let's say a game like Contra (everyone has played that game :p).

GameManager class (manages player/enemy locations)

Player class (two objects will be instianted, since it's a two player game)

Enemy class (many objects will instantiated, since there are many enemies you have to shoot)

Game Manager will manage all the locations and interactions between the players and the enemies.

Is there any way to keep the GameManager object alive to receive/distribute data syncronously with the clients?

Since it's "bad practice" to use syncronous calls with a XMLHttpRequest object, I was thinking perhaps a live PHP object can act as the syncronous middle tier and then connect to the DB.
Copy linkTweet thisAlerts:
@NogDogSep 16.2006 — Just to clarify for my understanding: are you trying to share one object among multiple users, or persist an object across multiple requests for the same user?
Copy linkTweet thisAlerts:
@BuezaWebDevauthorSep 16.2006 — Just to clarify for my understanding: are you trying to share one object among multiple users, or persist an object across multiple requests for the same user?[/QUOTE]

That's a good question--It's both.

Persist an object across multiple requests and multiple users. The manager object can allow multiple clients to make multiple requests to it.
Copy linkTweet thisAlerts:
@chazzySep 16.2006 — you're looking for two different things and they need to be implemented separately.

as far as i am aware, php objects will only stay alive while the script is running, so you need to create a daemon script to run.
Copy linkTweet thisAlerts:
@BuezaWebDevauthorSep 16.2006 — Any alternative situations/setups that I can use to achieve this goal?

Perhaps instead of a constant connection, I could set a timer for each client to retrieve updates from the manager class? This would not achieve true "real-time" though.
Copy linkTweet thisAlerts:
@JohnPearceyNov 18.2010 — I've had the same problem which I've recently solved if anyone is interested. I have a huge amount of Java code and wanted to use it when writing websites for which I prefer PHP. So, I've written a middleware server which I'm thinking about distributing under GPL. I've written both PHP and Java clients to communicate with it using RPC style calls. The PHP can work stand-alone or on web pages. The middleware maintains state/session etc.. It is being used in two websites currently. I did this because the php/java project seems now unsupported and I think tomcat is rubbish. I am looking at JBoss at the mo but don't see any PHP support so this would require writing the IIOR stuff. I did also find a small php-java lib that someone wrote using cut-down xml calls, quite fast too. If anyone wants any help or advise, or can help me stop re-inventing wheels, drop me a line: john at pearcey dot net.
Copy linkTweet thisAlerts:
@svidgenNov 18.2010 — If you're looking to avoid database interaction (though not necessarily a bad solution), you might consider installing APC: http://www.php.net/manual/en/book.apc.php

At each page load, check for the object in the cache -- if it's not present, initialize it however you need to. I'm not sure how you'd handle modifications to the shared variable (which could be an object) though. I have no idea offhand whether PHP performs any locking, provides any semaphore or mutex structures.

I would actually recommend just using the database for this. It will store commonly accessed records in memory, making access to them pretty efficient. And you can then lean on the database locking and transaction mechanisms -- even down to single attributes of the shared object, if implemented in a somewhat normalized form.


ADDENDUM: A database will also allow objects to be shared across web servers -- something that a caching mechanism won't facilitate very gracefully. Though, I suppose if you encounter the need for multiple web servers, you may already be encountering the need to (re)architect your application to avoid [I]globally[/I] shared objects.

ANOTHER ADDENDUM: Installing APC will also [drastically] improve the general performance of your app. Java may typically outperform PHP on account of using precompiled opcodes, eliminating the need for [I]complex[/I] parsing and optimization at runtime. Java may also keep the application resident in memory, which is significant. (enter my ignorance of Java server technologies). However, APC will give PHP similar advantages by keeping PHP opcodes resident in memory after the initial load of each used file.
×

Success!

Help @BuezaWebDev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...