How is stored resource type in php
How stored Resource type in php? Is it string in memory or some structure ?
In documentation
A resource is a special variable, holding a reference to an external
resource.
How it works in php environment?
php c
|
show 1 more comment
How stored Resource type in php? Is it string in memory or some structure ?
In documentation
A resource is a special variable, holding a reference to an external
resource.
How it works in php environment?
php c
For example a variable storing a MySQL connection result from callingmysqli_connect
. To quote: "Resources are created and used by special functions. File and database resources are defined by the PHP interpreter and are only accessible by functions provided by the interpreter" Reference: informit.com/articles/article.aspx?p=680835
– Gary Thomas
Jan 3 at 17:25
@GaryThomas yes, you right, i know it. But my question is how generate resource in php Core.
– user10863728
Jan 3 at 17:34
1
I think resources are implemented as integers, and they're indexes into tables in the PHP core.
– Barmar
Jan 3 at 17:44
1
It's aresource
type. It's a reference to functionality internal to the PHP engine that is not otherwise accessible to your code. It has no other meaningful structure that you need to be aware of when writing PHP code.
– Sammitch
Jan 3 at 18:15
stackoverflow.com/questions/30258470/…
– deceze♦
Jan 3 at 21:47
|
show 1 more comment
How stored Resource type in php? Is it string in memory or some structure ?
In documentation
A resource is a special variable, holding a reference to an external
resource.
How it works in php environment?
php c
How stored Resource type in php? Is it string in memory or some structure ?
In documentation
A resource is a special variable, holding a reference to an external
resource.
How it works in php environment?
php c
php c
edited Jan 4 at 11:01
Konstantin Okhotnick
1,337922
1,337922
asked Jan 3 at 17:17
user10863728
For example a variable storing a MySQL connection result from callingmysqli_connect
. To quote: "Resources are created and used by special functions. File and database resources are defined by the PHP interpreter and are only accessible by functions provided by the interpreter" Reference: informit.com/articles/article.aspx?p=680835
– Gary Thomas
Jan 3 at 17:25
@GaryThomas yes, you right, i know it. But my question is how generate resource in php Core.
– user10863728
Jan 3 at 17:34
1
I think resources are implemented as integers, and they're indexes into tables in the PHP core.
– Barmar
Jan 3 at 17:44
1
It's aresource
type. It's a reference to functionality internal to the PHP engine that is not otherwise accessible to your code. It has no other meaningful structure that you need to be aware of when writing PHP code.
– Sammitch
Jan 3 at 18:15
stackoverflow.com/questions/30258470/…
– deceze♦
Jan 3 at 21:47
|
show 1 more comment
For example a variable storing a MySQL connection result from callingmysqli_connect
. To quote: "Resources are created and used by special functions. File and database resources are defined by the PHP interpreter and are only accessible by functions provided by the interpreter" Reference: informit.com/articles/article.aspx?p=680835
– Gary Thomas
Jan 3 at 17:25
@GaryThomas yes, you right, i know it. But my question is how generate resource in php Core.
– user10863728
Jan 3 at 17:34
1
I think resources are implemented as integers, and they're indexes into tables in the PHP core.
– Barmar
Jan 3 at 17:44
1
It's aresource
type. It's a reference to functionality internal to the PHP engine that is not otherwise accessible to your code. It has no other meaningful structure that you need to be aware of when writing PHP code.
– Sammitch
Jan 3 at 18:15
stackoverflow.com/questions/30258470/…
– deceze♦
Jan 3 at 21:47
For example a variable storing a MySQL connection result from calling
mysqli_connect
. To quote: "Resources are created and used by special functions. File and database resources are defined by the PHP interpreter and are only accessible by functions provided by the interpreter" Reference: informit.com/articles/article.aspx?p=680835– Gary Thomas
Jan 3 at 17:25
For example a variable storing a MySQL connection result from calling
mysqli_connect
. To quote: "Resources are created and used by special functions. File and database resources are defined by the PHP interpreter and are only accessible by functions provided by the interpreter" Reference: informit.com/articles/article.aspx?p=680835– Gary Thomas
Jan 3 at 17:25
@GaryThomas yes, you right, i know it. But my question is how generate resource in php Core.
– user10863728
Jan 3 at 17:34
@GaryThomas yes, you right, i know it. But my question is how generate resource in php Core.
– user10863728
Jan 3 at 17:34
1
1
I think resources are implemented as integers, and they're indexes into tables in the PHP core.
– Barmar
Jan 3 at 17:44
I think resources are implemented as integers, and they're indexes into tables in the PHP core.
– Barmar
Jan 3 at 17:44
1
1
It's a
resource
type. It's a reference to functionality internal to the PHP engine that is not otherwise accessible to your code. It has no other meaningful structure that you need to be aware of when writing PHP code.– Sammitch
Jan 3 at 18:15
It's a
resource
type. It's a reference to functionality internal to the PHP engine that is not otherwise accessible to your code. It has no other meaningful structure that you need to be aware of when writing PHP code.– Sammitch
Jan 3 at 18:15
stackoverflow.com/questions/30258470/…
– deceze♦
Jan 3 at 21:47
stackoverflow.com/questions/30258470/…
– deceze♦
Jan 3 at 21:47
|
show 1 more comment
1 Answer
1
active
oldest
votes
Types in PHP implementation throuth base structure ZVAL.
Every type is structure ZVAL (Zend value).
As we know
A resource is a special variable, holding a reference to an external
resource. Resources are created and used by special functions.
for example fopen
return type resurce.
$fp = fopen('/proc/cpuinfo', 'r');
$fp - is Resource type, it means in the php core have created composition data by structure:
struct _zend_resource {
zend_refcounted_h gc;
int handle;
int type;
void *ptr;
};
Where zend_refcounted_h
- header of our type, it done for memory managment and represents hash;handle
is an integer that is used internally by the engine to locate the resource into an internal resource table. Php create it in process creating resource.
The type
is used to regroup resources of the same type together. It means we need call destructor of resource and it helps us to find registered destructor.ptr
it is our abstraction data.
Stage creating resource:
1. Registration destructor with zend_register_list_destructors_ex()
. it needs for cleaning memory in garbage collector.
2. Register new resource zend_register_resource()
and attach pointer to destructor. It is our type that returned zend_register_list_destructors_ex()
full example.
static void file_destructor(zend_resource *rsrc)
{
fclose((FILE *)rsrc->ptr);
}
type = zend_register_list_destructors_ex(
file_destructor, // pointer to destructor
NULL, // pointer to destructor for persistent resource, that non deleted after end request (example BD connection resource)
"file_resource", // name
module_number // PHP extension number
);
fp = fopen("/proc/cpuinfo", "r");
file_resource = zend_register_resource((void *)fp, type);
ZVAL_RES(&my_val, file_resource);
Resource types are just a way for the engine to mix different kind of
resources (of type “file”, “gzip” or even “mysql connection”) into the
same resource table.
More details about Resource type, creating, deleting and working in phpinternalsbook
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026901%2fhow-is-stored-resource-type-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Types in PHP implementation throuth base structure ZVAL.
Every type is structure ZVAL (Zend value).
As we know
A resource is a special variable, holding a reference to an external
resource. Resources are created and used by special functions.
for example fopen
return type resurce.
$fp = fopen('/proc/cpuinfo', 'r');
$fp - is Resource type, it means in the php core have created composition data by structure:
struct _zend_resource {
zend_refcounted_h gc;
int handle;
int type;
void *ptr;
};
Where zend_refcounted_h
- header of our type, it done for memory managment and represents hash;handle
is an integer that is used internally by the engine to locate the resource into an internal resource table. Php create it in process creating resource.
The type
is used to regroup resources of the same type together. It means we need call destructor of resource and it helps us to find registered destructor.ptr
it is our abstraction data.
Stage creating resource:
1. Registration destructor with zend_register_list_destructors_ex()
. it needs for cleaning memory in garbage collector.
2. Register new resource zend_register_resource()
and attach pointer to destructor. It is our type that returned zend_register_list_destructors_ex()
full example.
static void file_destructor(zend_resource *rsrc)
{
fclose((FILE *)rsrc->ptr);
}
type = zend_register_list_destructors_ex(
file_destructor, // pointer to destructor
NULL, // pointer to destructor for persistent resource, that non deleted after end request (example BD connection resource)
"file_resource", // name
module_number // PHP extension number
);
fp = fopen("/proc/cpuinfo", "r");
file_resource = zend_register_resource((void *)fp, type);
ZVAL_RES(&my_val, file_resource);
Resource types are just a way for the engine to mix different kind of
resources (of type “file”, “gzip” or even “mysql connection”) into the
same resource table.
More details about Resource type, creating, deleting and working in phpinternalsbook
add a comment |
Types in PHP implementation throuth base structure ZVAL.
Every type is structure ZVAL (Zend value).
As we know
A resource is a special variable, holding a reference to an external
resource. Resources are created and used by special functions.
for example fopen
return type resurce.
$fp = fopen('/proc/cpuinfo', 'r');
$fp - is Resource type, it means in the php core have created composition data by structure:
struct _zend_resource {
zend_refcounted_h gc;
int handle;
int type;
void *ptr;
};
Where zend_refcounted_h
- header of our type, it done for memory managment and represents hash;handle
is an integer that is used internally by the engine to locate the resource into an internal resource table. Php create it in process creating resource.
The type
is used to regroup resources of the same type together. It means we need call destructor of resource and it helps us to find registered destructor.ptr
it is our abstraction data.
Stage creating resource:
1. Registration destructor with zend_register_list_destructors_ex()
. it needs for cleaning memory in garbage collector.
2. Register new resource zend_register_resource()
and attach pointer to destructor. It is our type that returned zend_register_list_destructors_ex()
full example.
static void file_destructor(zend_resource *rsrc)
{
fclose((FILE *)rsrc->ptr);
}
type = zend_register_list_destructors_ex(
file_destructor, // pointer to destructor
NULL, // pointer to destructor for persistent resource, that non deleted after end request (example BD connection resource)
"file_resource", // name
module_number // PHP extension number
);
fp = fopen("/proc/cpuinfo", "r");
file_resource = zend_register_resource((void *)fp, type);
ZVAL_RES(&my_val, file_resource);
Resource types are just a way for the engine to mix different kind of
resources (of type “file”, “gzip” or even “mysql connection”) into the
same resource table.
More details about Resource type, creating, deleting and working in phpinternalsbook
add a comment |
Types in PHP implementation throuth base structure ZVAL.
Every type is structure ZVAL (Zend value).
As we know
A resource is a special variable, holding a reference to an external
resource. Resources are created and used by special functions.
for example fopen
return type resurce.
$fp = fopen('/proc/cpuinfo', 'r');
$fp - is Resource type, it means in the php core have created composition data by structure:
struct _zend_resource {
zend_refcounted_h gc;
int handle;
int type;
void *ptr;
};
Where zend_refcounted_h
- header of our type, it done for memory managment and represents hash;handle
is an integer that is used internally by the engine to locate the resource into an internal resource table. Php create it in process creating resource.
The type
is used to regroup resources of the same type together. It means we need call destructor of resource and it helps us to find registered destructor.ptr
it is our abstraction data.
Stage creating resource:
1. Registration destructor with zend_register_list_destructors_ex()
. it needs for cleaning memory in garbage collector.
2. Register new resource zend_register_resource()
and attach pointer to destructor. It is our type that returned zend_register_list_destructors_ex()
full example.
static void file_destructor(zend_resource *rsrc)
{
fclose((FILE *)rsrc->ptr);
}
type = zend_register_list_destructors_ex(
file_destructor, // pointer to destructor
NULL, // pointer to destructor for persistent resource, that non deleted after end request (example BD connection resource)
"file_resource", // name
module_number // PHP extension number
);
fp = fopen("/proc/cpuinfo", "r");
file_resource = zend_register_resource((void *)fp, type);
ZVAL_RES(&my_val, file_resource);
Resource types are just a way for the engine to mix different kind of
resources (of type “file”, “gzip” or even “mysql connection”) into the
same resource table.
More details about Resource type, creating, deleting and working in phpinternalsbook
Types in PHP implementation throuth base structure ZVAL.
Every type is structure ZVAL (Zend value).
As we know
A resource is a special variable, holding a reference to an external
resource. Resources are created and used by special functions.
for example fopen
return type resurce.
$fp = fopen('/proc/cpuinfo', 'r');
$fp - is Resource type, it means in the php core have created composition data by structure:
struct _zend_resource {
zend_refcounted_h gc;
int handle;
int type;
void *ptr;
};
Where zend_refcounted_h
- header of our type, it done for memory managment and represents hash;handle
is an integer that is used internally by the engine to locate the resource into an internal resource table. Php create it in process creating resource.
The type
is used to regroup resources of the same type together. It means we need call destructor of resource and it helps us to find registered destructor.ptr
it is our abstraction data.
Stage creating resource:
1. Registration destructor with zend_register_list_destructors_ex()
. it needs for cleaning memory in garbage collector.
2. Register new resource zend_register_resource()
and attach pointer to destructor. It is our type that returned zend_register_list_destructors_ex()
full example.
static void file_destructor(zend_resource *rsrc)
{
fclose((FILE *)rsrc->ptr);
}
type = zend_register_list_destructors_ex(
file_destructor, // pointer to destructor
NULL, // pointer to destructor for persistent resource, that non deleted after end request (example BD connection resource)
"file_resource", // name
module_number // PHP extension number
);
fp = fopen("/proc/cpuinfo", "r");
file_resource = zend_register_resource((void *)fp, type);
ZVAL_RES(&my_val, file_resource);
Resource types are just a way for the engine to mix different kind of
resources (of type “file”, “gzip” or even “mysql connection”) into the
same resource table.
More details about Resource type, creating, deleting and working in phpinternalsbook
edited Jan 4 at 9:14
answered Jan 3 at 21:23
Konstantin OkhotnickKonstantin Okhotnick
1,337922
1,337922
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54026901%2fhow-is-stored-resource-type-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
For example a variable storing a MySQL connection result from calling
mysqli_connect
. To quote: "Resources are created and used by special functions. File and database resources are defined by the PHP interpreter and are only accessible by functions provided by the interpreter" Reference: informit.com/articles/article.aspx?p=680835– Gary Thomas
Jan 3 at 17:25
@GaryThomas yes, you right, i know it. But my question is how generate resource in php Core.
– user10863728
Jan 3 at 17:34
1
I think resources are implemented as integers, and they're indexes into tables in the PHP core.
– Barmar
Jan 3 at 17:44
1
It's a
resource
type. It's a reference to functionality internal to the PHP engine that is not otherwise accessible to your code. It has no other meaningful structure that you need to be aware of when writing PHP code.– Sammitch
Jan 3 at 18:15
stackoverflow.com/questions/30258470/…
– deceze♦
Jan 3 at 21:47