How is stored resource type in php












3















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?










share|improve this question

























  • 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
















3















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?










share|improve this question

























  • 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














3












3








3








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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



















  • 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

















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












1 Answer
1






active

oldest

votes


















3














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;
handleis 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.
ptrit 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






share|improve this answer


























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    3














    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;
    handleis 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.
    ptrit 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






    share|improve this answer






























      3














      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;
      handleis 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.
      ptrit 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






      share|improve this answer




























        3












        3








        3







        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;
        handleis 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.
        ptrit 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






        share|improve this answer















        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;
        handleis 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.
        ptrit 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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 4 at 9:14

























        answered Jan 3 at 21:23









        Konstantin OkhotnickKonstantin Okhotnick

        1,337922




        1,337922
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas