tags:

views:

58

answers:

6

hello,

i have a query that, how can i transfer an object from php file A to php file B?. but i know a solution using session.But what i need to know is, is their any other method to transfer object between php files other than session?

+1  A: 

Save in a file, save in a database, save in shared memory, save in a cache server.

Ignacio Vazquez-Abrams
can you explain about saving in shared memory and saving in a cache server.
Jaison Justus
http://php.net/manual/en/book.shmop.php http://php.net/manual/en/book.memcache.php
Ignacio Vazquez-Abrams
Using memcached.. "Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects)"
RobertPitt
Bear in mind Memcached for a single server setup is pointless (has a tcp/ip overhead)
Kieran Allen
+1  A: 

One way is to store the serialized object - or its data - into a database, using the session ID as the key to "find" it again.

The same could be done using a cache file.

A faster way is using a shared memory cache like memcache. These solutions always require server-side administration and root access to set up.

Pekka
A: 

Serialize the object and store in one of the following (Database,Temp,Memcache).

Depending on what the object consists of i would take a look at implementing the __sleep and __wake magic methods to make sure the object is able to be transferred correctly.

RobertPitt
A: 

Hi,

by using cURL you can transfer any thing... try this..

http://php.net/manual/en/book.curl.php
VAC-Prabhu
I dont think the OP Means by Cross Server requests, Who would want to send objects across HTTP Anyway?
RobertPitt
@RobertPitt: By first `serializing` them, for example.
nikic
objects can be very huge, i know you can serialize them before sending them, but there still can be very very large and will sometimes override the Apaches HTTP_VARS Max allowed char etc, i personally would store the file locally, ping the server with an address of the temp file, then use curl to get the file, and then ping back to the server to delete.
RobertPitt
A: 

The easiest way (besides using sessions) is probably to save it as an APC (Alternative PHP Cache) user variable, as you probably will install APC for opcode caching purposes already. This way you have one extension for two things.

APC stores values inmemory as Memcached does, but is way easier to install, because it's not an extra daemon running, but a PHP extension.

nikic
+1  A: 

APC is probabaly the easiest method:

example:

// new object
$object = new ClassName('Kieran', 123);

// Store it
apc_store('object', $object); 

The other script

$obj = apc_fetch('object');
print_r($obj->method());
Kieran Allen
is APC avail in all hosting servers... or we need to install or some do something else
Jaison Justus
Check phpinfo(); If it isn't i recommend installing it.
Kieran Allen
Itrs abailable in PHP 5.3, You just have to enable it in your php.ini under `apc.dll` If it does not exists you can get it here http://pecl.php.net/package/apc
RobertPitt