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

search for in the

NULL> <Обекти
Last updated: Fri, 27 Jun 2008

view this page in

Ресурс

Ресурсът е специална променлива, която държи референция към външен източник. Ресурсите се създават и биват използвани посредством специални функции. Вижте приложението за списък с всички тези функции и съответните ресурсни типове.

Забележка: Типът ресурс беше въведен в PHP 4

Вж. също get_resource_type().

Преобразуване в ресурс

Тъй като ресурсите държат специални манипулатори към отворени файлове, връзки към бази от данни, изображения и т.н., преобразуването на каквато и да е стойност в ресурс не е възможно.

Освобождаване на ресурси

Благодарение на системата за броене на референции, въведена в Zend Engine на PHP 4, случаи, в които няма останали референции към даден ресурс, се откриват автоматично (също като в Java). В този случай всички източници, които са били използвани от този ресурс, се освобождават от боклукчията (garbage collector). Затова, рядко се налага паметта да бъде освобождавана ръчно, посредством някоя функция от рода free_result.

Забележка: Постоянните връзки към бази от данни са специални - те не се унищожават от боклукчията. Вижте и раздела относно постоянни връзки.



NULL> <Обекти
Last updated: Fri, 27 Jun 2008
 
add a note add a note User Contributed Notes
Ресурс
adrian dot dziubek at gmail dot com
07-Jul-2008 09: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 11: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 02: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> <Обекти
Last updated: Fri, 27 Jun 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites