Page 1 of 2
Really Tricky Question: Trust Me
Posted: Tue Jan 02, 2007 3:31 pm
by BIGjuevos
How does one save a resource(such as a socket) within a class based object from one script for use within another script which is later executed.
OK, before you start asking me questions, let me state what I know:
-The PHP website says that you cannot store a resource in a session, which I tried and found out the hard way.
-You cannot serialize a resource and store it on the filesystem, tried that too.
-I don't know how to do binary operations on the filesystem with PHP.
Possible Solutions, which I don't know how to implement
-Could I save the class/resource to the file system in it's entirety and be restored later.
OK, that's all I have. I have faith in you gurus. So please help this intermediate user out!
Thanks in advance,
Ryan
Posted: Tue Jan 02, 2007 3:34 pm
by volka
BIGjuevos wrote:Possible Solutions, which I don't know how to implement
-Could I save the class/resource to the file system in it's entirety and be restored later.
No, you cannot.
Posted: Tue Jan 02, 2007 3:37 pm
by BIGjuevos
volka wrote:BIGjuevos wrote:Possible Solutions, which I don't know how to implement
-Could I save the class/resource to the file system in it's entirety and be restored later.
No, you cannot.
Any suggestios?
I am completely open.
Posted: Tue Jan 02, 2007 3:41 pm
by volka
You have to store something else than a resource, e.g. host, port and protocoll (as strings and numbers) to re-create the socket.
Posted: Tue Jan 02, 2007 3:47 pm
by Kieran Huggins
BIGjuevos wrote:I am completely open.
Maybe you could open a socket in UNIX and read/write to it from PHP?
You could even create the socket from within PHP if you have permissions.
Posted: Tue Jan 02, 2007 3:49 pm
by BIGjuevos
That's the problem, I'm not looking to re-connect, I am looking to "re-open" the socket seconds later in another script.
Posted: Tue Jan 02, 2007 3:52 pm
by BIGjuevos
Kieran Huggins wrote:BIGjuevos wrote:I am completely open.
Maybe you could open a socket in UNIX and read/write to it from PHP?
You could even create the socket from within PHP if you have permissions.
But how do I transfer the resource from the script that ended that created the socket to the script that is now running that want to use that same open socket?
Posted: Tue Jan 02, 2007 4:34 pm
by Kieran Huggins
Everything in UNIX (including sockets) are treated as files.
I would use a session variable to point to the existing open socket "file". Then a quick fopen('/path/to/socket.file'); would give you access to your existing socket.
You may want to include a unique variable in the filename of the socket file to keep concurrent sessions from colliding.
Read
http://www.cs.rpi.edu/courses/sysprog/sockets/sock.html for more info on sockets in UNIX
(upon further reading, this seems to be a C reference)
Posted: Tue Jan 02, 2007 5:16 pm
by RobertGonzalez
So you are wanting to use a resource created in one script to be used in another, unrelated script that executes after the creating script has already terminated?
Posted: Tue Jan 02, 2007 5:18 pm
by volka
Kieran Huggins wrote:Everything in UNIX (including sockets) are treated as files.
I would use a session variable to point to the existing open socket "file". Then a quick fopen('/path/to/socket.file'); would give you access to your existing socket.
That's only true for unix sockets, not for at_inet
Posted: Tue Jan 02, 2007 5:23 pm
by Kieran Huggins
volka wrote:That's only true for unix sockets, not for at_inet
I have NO experience doing this - trust volka!
Posted: Tue Jan 02, 2007 6:07 pm
by Ollie Saunders
Sounds like you want a persistent connection.
Is
pfsockopen any use?
Posted: Tue Jan 02, 2007 8:55 pm
by Christopher
ole! Ouch!
RTQ or RTFM?
In defense of RTQ ... there is a Socket section in the manual and then there are five socket functions in the Network section.
Posted: Tue Jan 02, 2007 9:08 pm
by Ollie Saunders
Huh?
OK I'm guessing RTQ stands for "read the question".
Based on this
That's the problem, I'm not looking to re-connect, I am looking to "re-open" the socket seconds later in another script.
I suggested persistent connections. If that was incredibly stupid suggestion for some reason...well I've never used sockets before and please educate me

Posted: Tue Jan 02, 2007 10:03 pm
by Kieran Huggins
I have no idea what RTQ is either... but you totally gave us all a swift kick on that one

I had no idea there was a pfsockopen()!
Good to know!
