bensiu
bensiu

Reputation: 25604

PHP object exchange between servers

I got script what read from database and manipulate it so on the end I got $result array... on one server

is it possible to serialize this object and pass it to other script so this $result array could be available for other script on second server...

I got on first server:

return serialize ( $results );

and on second:

$data = unserialize ( file_get_contents ( 'http://www.......com/reader.php' ) );

...but there is no communication between .... What I am doing wrong ?

Bensiu

Upvotes: 0

Views: 197

Answers (1)

netcoder
netcoder

Reputation: 67735

Yes, you can. For arrays, you can simply use JSON, via json_encode. It is less error prone than serialize. However, you will have to output it (e.g.: echo), instead of returning it, for file_get_contents to be able to grab a result.

Instead of:

return serialize($results);

I'd suggest:

echo json_encode($results);

Then you could do:

$data = json_decode(file_get_contents('http://www.......com/reader.php'), true);

Upvotes: 2

Related Questions