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

search for in the

NULL> <Objetos
Last updated: Fri, 22 Aug 2008

view this page in

Recursos

Un valor tipo resource es una variable especial, que contiene una referencia a un recurso externo. Los recursos son creados y usados por funciones especiales. Vea el apéndice para un listado de todas estas funciones y los tipos resource correspondientes.

Note: El tipo resource fue introducido en PHP 4

Vea también la función get_resource_type().

Conversión a recurso

Dado que las variables resource contienen gestores especiales a archivos abiertos, conexiones con bases de datos, áreas de pintura de imágenes y cosas por el estilo, la conversión a tipo resource carece de sentido.

Liberación de recursos

Gracias al sistema de conteo de referencias introducido con el Motor Zend de PHP 4, un recurso que ya no es referenciado es detectado automáticamente, y es liberado por el recolector de basura. Por esta razón, rara vez se necesita liberar la memoria manualmente.

Note: Los enlaces persistentes con bases de datos son una excepción a esta regla. Ellos no son destruidos por el recolector de basura. Vea también la sección sobre conexiones persistentes para más información.



NULL> <Objetos
Last updated: Fri, 22 Aug 2008
 
add a note add a note User Contributed Notes
Recursos
adrian dot dziubek at gmail dot com
07-Jul-2008 05: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 07: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 10: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> <Objetos
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites