1

I have a web application that I am writing that loads the configuration database into shared memory for fast access. The problem that I am running into is that there seems to be a disconnect between the shared memory when running from the web server (Apache in this case) and when I run it from the command line using php -f. This is being developed on a Windows 10 machine, but the production server runs Unix. It seems to work under Unix though.

The only relevant information that I have been able to find was this question here on StackOverflow. I know that shared memory operations between Unix and Windows is fundamentally different, but when I use the same ID (key) to identify the shared memory region, shouldn't it access that same region regardless of the execution environment?

I know this works under Unix because I have tried it. One of the other developers uses a Macintosh and it works there too. Windows doesn't seem to work. The PHP Manual states that shared memory isn't available on Windows versions prior to 2000.

So is the disconnect in shared memory between CLI and Web on Windows something inherent to the platform? The answer in the linked question seems to indicate yes, but that was asked in 2009. In the 9+ years since then, is this still the same?

This is running Windows 10, Apache 2.4, PHP 7.2, and MySQL 5.17.

I don't know too much about Windows programming since I do come from a Unix environment and I have used System V shared memory for IPC in the past.

2
  • Do you have all the same extensions configured in the php.ini file the CLI uses that the php.ini for the web uses? Commented Jul 5, 2018 at 16:48
  • @MrGlass I believe so. The CLI program doesn't error out when I run it, so it is getting there without problems. Commented Jul 6, 2018 at 0:02

1 Answer 1

0

After fighting it for some time, I figured it out.

WINDOWS

It turns out that since Windows doesn't have Unix style shared memory, PHP simulates it. Because of this, the shared memory of PHP running under Apache, and from the command line are separated.

UNIX

It does work as expected under Unix though. The PHP context running from Apache and running from the command line both use the same region since Unix supports proper shared memory.

THE FIX

For Windows, there isn't one because the platform simply does not support it. So I just have to accept that the command line tools that I have written in PHP just won't work under Windows. They will have to be tested under Unix for proper functionality.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.