PHP RMI for a class


I have made a class file which are running on my server.I am using it as a some client will use it.In their program i have to create an object remotely of this class. How will use my class file as RMI that object can create easily on other server. Thanks




I don't think anything close to Java's RMI (as far as I understand it) can be done in PHP.

The best thing that comes to my mind is

  • Create an object in the remote script

  • Serialize that object

  • Return the serialized data to the calling script

  • Unserialize the data back into an object (note that all class definitions must be present locally for this to work!)

Note that things like active database connections, file handles and so on can not be transferred this way.

Whether this is a good - and fast enough - way to do what you want is hard to say. Maybe it helps.




To connect as a user other than 'anonymous', you need to specify the username (and possibly password) within the URL, such as 'ftp://user:[email protected]/path/to/file'. (You can use the same sort of syntax to access files via HTTP when they require Basic authentication.)

$file = fopen ("", "w");
if (!$file) {
    echo "<p>Unable to open remote file for writing.\n";
/* Write the data here. */
fwrite ($file, $_SERVER['HTTP_USER_AGENT'] . "\n");
fclose ($file);

include ("ftp://username:[email protected]/public_html/example.php");    
$class = new Ford();    
$dataRow = $class->consulta();

People are also looking for solutions to the problem: php - How to treat exceptions in constructor best?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.