Really Tricky Question: Trust Me
Moderator: General Moderators
Really Tricky Question: Trust Me
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
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
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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?Kieran Huggins wrote:Maybe you could open a socket in UNIX and read/write to it from PHP?BIGjuevos wrote:I am completely open.
You could even create the socket from within PHP if you have permissions.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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)
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)
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Sounds like you want a persistent connection.
Is pfsockopen any use?
Is pfsockopen any use?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Huh? 
OK I'm guessing RTQ stands for "read the question".
Based on this
OK I'm guessing RTQ stands for "read the question".
Based on this
I suggested persistent connections. If that was incredibly stupid suggestion for some reason...well I've never used sockets before and please educate meThat's the problem, I'm not looking to re-connect, I am looking to "re-open" the socket seconds later in another script.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact: