SHMOP series functions using PHP Shared Memory implementation method

Source: Internet
Author: User
Shmop, is an easy-to-use feature set that allows PHP to read, write, create, and delete Unix shared memory segments. This article is mainly to share with you SHMOP series functions using PHP Shared Memory implementation method, hope to help everyone.

1. SHMOP series functions use <?php//to use SHMOP series functions Set_time_limit (0), $shm _key = Ftok (__file__, ' t '), $shm _id = Shmop_open ($shm _key, "c ", 0655, 1024x768); $size = Shmop_write ($shm _id," Hello World ". Php_eol, 0); Shmop_write ($shm _id, ' I love you '. Php_eol, $size + 1); Echo $size. php_eol; $data = Shmop_read ($shm _id, 0, +), Var_dump ($data), Shmop_delete ($shm _id); Shmop_close ($shm _id);//shared  Memory functions/** * Shmop_open (int $key, string $flags, int $mode, int $size) * $key shared Memory key * $flags value has the following types of * a: Creates a read-only shared memory area. * C: If the shared memory area already exists, open the shared memory area and try to read and write. Otherwise new shared memory area * W: Create a read/write shared memory area * N: Create a shared memory area, if it already exists, return failure * * $mode read and Write permissions. such as 0755 0644 * $size request the size of the shared memory area *//** * Shmop_read (resource $shmid, int $start, int $count) * will read data from the shared memory block * $shmid share inside Save ID, Resource type * $start start reading from the byte of shared memory * $count How many bytes are read at a time. * If the count value is less than the length of information sent, the information is truncated.  *//** * Shmop_write (Resource $shmid, string $data, int $offset) * Writes data to a shared memory block * $data the data to be written * $offset start writing from that location in the shared memory block. * The return value of this function is the length of the write data. *//** * Shmop_size (Resource $shmid); * Returns the current shared memory block,Already used size *//** * shmop_delete (Resource $shmid) * Delete a shared memory block, delete reference relationship *//** * Shmop_close (Resource $shmid) * Close shared memory block * to Use Shmop_delete to continue using Shmop_close */2, SHM series functions using <?php//to expand shared memory $key = Ftok (__file__, ' a '), $share _key = 1;// Create a shared memory with a size of 1024 bytes and a permission of 755$shm_id = Shm_attach ($key, 1024, 0755);//Put a key=>value in shared memory $message1 = "I Love Roverliang "; Shm_put_var ($shm _id, $share _key, $message 1);//re-use key, the value of the previous setting is overwritten by the value of the latter setting. $message 2 = "I love Rover"; Shm_put_var ($shm _id, $share _key, $message 2);//read a shared memory value $read_message = Shm_get_var ($shm _id, $share _key); Echo $read _message. Php_eol;//was not taken away, but read $read_message2 = Shm_get_var ($shm _id, $share _key); Echo $read _message2. php_eol;//determines whether a value exists in shared memory $isexists = Shm_has_var ($shm _id, $share _key); Var_dump ($isexists);//Delete a value Shm_remove_var ($ shm_id, $share _key);//Determine if a value exists in shared memory $isexists = Shm_has_var ($shm _id, $share _key); Var_dump ($isexists);// Delete a shared memory Shm_remove ($SHM _id);//Close the Shared Memory connection Shm_detach ($shm _id);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.