Hacking the PHP Source |
|
2024-11-24 |
|
|
19 |
|
|
A generic data container. Used to hold file handles, database connections, or
anything else that needs to be initialized and then passed around for other
functions to act on. To create a resource in your extension, first declare
an extension-wide true global. We don't have to worry about thread-safety here.
And then if your resource holds a complex datatype of some sort, typedef it as
well at the top of your .c file (on in your header file):
Next we need to create a resource destructor function.
Then in our MINIT function we declare/initialize our resource:
Then we might have a function that looks like this that returns a resource:
Followed by other functions that then take a resource as an argument and do something with it: