PHP RMI for a class

237

I have made a class file which are running on my server.I am using it as a API.my 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

800

Answer

Solution:

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.

80

Answer

Solution:

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.)

<?php
$file = fopen ("ftp://ftp.example.com/incoming/outputfile", "w");
if (!$file) {
    echo "<p>Unable to open remote file for writing.\n";
    exit;
}
/* Write the data here. */
fwrite ($file, $_SERVER['HTTP_USER_AGENT'] . "\n");
fclose ($file);
?>

http://php.net/manual/en/features.remote-files.php

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

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

Source

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.