RE: Having resource variables over several scripts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok, first let me disclaim that there are definitely a lot of people a lot smarter than me out there who may have figured this one out already, but as far as I know, resources like open file handles, database connection handles, objects, etc..  but especially anything that returns a resource number are not going to be carried over from one script execution to another.

If I recall properly, lets say script1.php opens a file, that's resource #1, then it opens a database connection, that's resource #2, etc..

Now let's say script2.php opens a database connection first, that's resource #1 for that script, then opens another database connection, that's resource #2, now it opens a file, that's resource #3..   

So the 'resource' number isn't tied to a certain type of handle (file, db connection, etc), it's based on the order of resources allocated.

That's only semi-related to what you're talking about, but thought it was worth mentioning.

But I believe all of these resources are freed up as soon as the script finishes executing thereby necessitating re-opening files, db connections, recreating objects, (maybe objects can be serialized, I forget) when the next script is executed.  No carry-over possible.


The solution?  Don't exit the script.  Unfortunately in an web environment you can't really keep a php script executing unless you create a php based server that your scripts connect to (doesn't have to be php based really.. just any server that listens and can keep files open for as long as they're needed).

Or maybe try to consolidate your file operations, in this case, so you can do it all in one pass.  Don't open a file, read one little thing, close it...  re-open it.. read something else... close it..  user makes changes..   opens file again.. writes changes.. closes it.      read once and write once..    See if you can streamline it somehow.

Just some thoughts off the top of my head.  Again, maybe someone else has a better answer, but I can't see how you'd avoid opening and closing each time unless you had a back-end server type program running.

-TG

= = = Original message = = =

Ben,

If you grab the resource and store it in a variable, you certainly should be
able to send it via GET or POST.  For that matter, you should be able to
store the information in a SESSION variable too, so I'm not sure what is
going wrong.  Could you email the code you are using to grab the resource
variable and the code to store it in a session?


- Jeff

-----Original Message-----
From: Benjamin Mack [mailto:benni@xxxxxxxxxxx] 
Sent: Monday, October 10, 2005 11:03 AM
To: php-general@xxxxxxxxxxxxx
Subject:  Having resource variables over several scripts

Hey,

I am trying to have e.g. a file opened over several scripts. When 
opening a file with "fopen" I receive a variable of the type resource 
(like "Resource ID #3"), but when I try to save this variable in the 
SESSION and try to use it on another page, I get a "null" variable.

Because I need to have the same and exact resource (not opened every 
time I load a new page) and since it is apparently not possible to store 
it in a session, I wanted to ask if somebody had the same issue once, 
and maybe there is some help out there.
Could I somehow serialize the resource, then give it to another page via 
GET or POST?

I would really appreciate if somebody has some hints...

Thanks,
benni.
-SDG-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux