Shared memory file in PHP

后端 未结 2 2065
走了就别回头了
走了就别回头了 2021-02-04 13:42

I use openssl_pkcs7_sign and openssl_pkcs7_encrypt to create encrypted data. The functions only accept file names. I would like to store the temporary

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 14:39

    Since Windows 2000, the shmop (previously shm_) methods are available.

    shmop_open uses a unique integer key to share the memory area. ftok can be used to produce a unique index based on a file path (typically your script file's full path). Any instance that shares the same key can share the same memory.

    http://php.net/manual/en/ref.shmop.php

    Tested on PHP Version 5.3.3 from Zend Server CE System Windows NT CRYPE 6.1 build 7601 (Unknow Windows version Business Edition Service Pack 1) i586

     'value');
    $bytes = shmop_write($memory, serialize($data), 0);
    $return = shmop_read($memory, 0, $bytes);
    print_r(unserialize($return));
    ?>
    

    shmop_read/shmop_write stores raw bytes from a string, so you don't need to serialize it, but you will need to write the length of the string somewhere. My example creates a 16KB shared memory area, you can of course size it to fit the openssl file plus the space you need to store the file size.

提交回复
热议问题