Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8574665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:31:28+00:00 2026-06-11T19:31:28+00:00

This code: shmop_delete(); shmop_close(); doesn’t delete shared memory. An experiment: $shmid = @shmop_open(1234, ‘a’,

  • 0

This code:

shmop_delete();
shmop_close();

doesn’t delete shared memory. An experiment:

$shmid = @shmop_open(1234, 'a', 0, 0);
var_dump($shmid);

yields

bool(false)

of course. But

$shmid = shmop_open(5678, 'c', 0644, 10);
...
shmop_delete($shmid);
shmop_close($shmid);
...
$shmid = @shmop_open(5678, 'a', 0, 0);
var_dump($shmid);

yields

int(157)

Why not deleted yet? How can I delete shared memory? I’m running apache on windows 7.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:31:30+00:00Added an answer on June 11, 2026 at 7:31 pm

    SHM is not natively available in Windows, so PHP tries to emulate it in its “thread safe resource manager” (TSRM) by using Windows File Mappings internally, which is an ugly hack (/TSRM/tsrm_win32.c).

    Therefore, the shmop extension uses the TSRM for SHM on Windows systems, too.
    shmop_delete() uses shmctl() with the IPC_RMID command to mark the memory segment destroyed, however IPC_RMID is implemented in the following way in the emulation:

        switch (cmd) {
                [...]
                case IPC_RMID:
                        if (shm->descriptor->shm_nattch < 1) {
                                shm->descriptor->shm_perm.key = -1;
                        }
                        return 0;
    

    where shm_nattch is the number of processes the segment is attached to (or at least what number the TSRM believes it to be). By setting shm_perm.keyto -1, subsequent access by shmget() is blocked until the Windows File Mapping is destroyed. However, when this code is called from shmop_delete(), there’s always at least the PHP process itself attached to the memory segment, so it effectively does nothing at all. The segment is only detached after you call shmop_close()

    So your answer is: Without fixing PHP, on Windows, you can’t delete shared memory.

    You can blame it on either on the SHM emulation in the TSRM, which is not posixly correct, or on the shmop extension for blindly using it.

    You can try to remove the if and set shm_perm.key to -1 unconditionally and recompile PHP. It can only break the shmop extension itself, the sysvshm extension or probably other extensions not distributed with PHP.

    Feel free to report that to the PHP bugtracker at http://bugs.php.net/ and have it fixed by someone more familiar with PHP internals.

    In the meantime, maybe http://www.php.net/w32api could help – you could use CreateFileMapping & friends from the Win32-API in a more direct manner with it. However, I have never tested it and in PECL it says it is not maintained , so be careful. It is also of course not portable.

    You could also try to wrap the shmop_* stuff into your own library and put your own deleted-flag in the beginning of the memory segment – the TSRM does something similar internally after all. But then you could run into a related bug: I think I remember someone reporting that he couldn’t create a segment with shmop_open() that was bigger than the last segment created using the same key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to create counter that using shared block memory, just look code: $i=0;
The php code is supposed to read the shared memory I create in a
This code below allows me to find the word error in all my files
This code is the core of a much larger script that works great in
This code disabled mouse scroll functionality, when i click on the document. $(document).on(click, function
This code only renders a dodecahedron and completely ignores the glBegin(GL_TRIANGLES) block: glutSolidDodecahedron(); glBegin(GL_TRIANGLES);
This code gives me this error:Cannot implicitly convert type ArrayList[] to ArrayList[][] at this
This code fails on some machines: // Parse error: syntax error, unexpected '[' ...
This code : http://jsfiddle.net/bYtTG/1/ Works as I want in FF, chrome and opera, but
This code is not pretty, but I want to print out the last generated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.