PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

NULL> <Objects
Last updated: Sun, 25 Nov 2007

view this page in

Resource

Μια resource είναι μια ειδική μεταβλητή, που κρατάει μια αναφορά σε μια εξωτερική resource. Οι resources δημιουργούνται και χρησιμοποιούνται από ειδικές συναρτήσεις. Δείτε το appendix για μια λίστα όλων αυτών των συναρτήσεων και των αντίστοιχων resource τύπων.

Note: Ο τύπος resource εισήχθη στην PHP 4

Μετατρέποντας σε resource

Επειδή οι resource τύποι έχουν ειδικούς handlers για ανοιγμένα αρχεία, database connections, image canvas areas και παρόμοια, δεν μπορείτε να μετατρέψετε οποιαδήποτε τιμή σε resource.

Ελευθερώνοντας resources

Εξαιτίας του reference-counting συστήματος που εισήχθη με την Zend-engine της PHP4, γίνεται αυτόματη ανίχνευση πότε σταματάει να γίνεται αναφορά σε ένα resource (όπως και στη Java). Σ'αυτή την περίπτωση, όλες οι resources που χρησιμοποιούνταν γι'αυτή τη resource ελευθερώνονται από τον garbage collector. Γι'αυτό το λόγο, είναι σπάνια αναγκαίο να ελευθερώσετε τη μνήμη manually χρησιμοποιώντας κάποια συνάρτηση όπως τη free_result.

Note: Τα Persistent database links είναι ιδιαίτερα, δεν καταστρέφονται από τον garbage collector. Δείτε επίσης το τμήμα σχετικά με σταθερές (persistent) συνδέσεις.



NULL> <Objects
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
Resource
adrian dot dziubek at gmail dot com
07-Jul-2008 08:55
I spent an hour trying to create mock setup for testing SQL queries. The explanation here, that a resource contains file handlers and therefore there is no sense in trying to create one is lame. Being unable to redefine functions, creating a fake resource was the second thing I tried to put test in place, but looking at the search results, I see I'm the first one to try... For me it looks like security by obscurity.
evildictaitor at hotmail dot com
16-Aug-2004 10:25
In response to yasuo_ohgaki, the reason for the inability of the $_SESSION[] variable to hold references is because a session is just a serialize()'d version of it's member variables saved under a unique filename, with this filename following the user around.

$_SESSION[] is therefore limited by the constraints of the serialize() function

Although this is not <i>strictly</i> true, ($_SESSION does some handling to convert messy variables (e.g. "s and ;s)) it cannot store resources due to the serialise() function's dependancy
isaac at chexbox dot com
22-Jun-2002 01:37
For the the oblivious: An example of a resource would be a mysql database connection.

$result = mysql_connect("localhost", "username", "pass");
//$result variable is a resource.

print $result;
//will print: Resource ID#1, or something similar

NULL> <Objects
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites