In using php shared memory and semaphores. How can I first check that the key for the semaphore and shared memory block, doesn’t collide with other instances of php? Also when using the shm_attach function to create a new block, is there a way to verify the block didn’t already already exist?
Share
I don’t really understand what you’re asking here. The whole point of shared memory is that it is shared – so being able to use the same key in different instances of PHP is pretty much a requirement.
Typically people use filesystem paths (semantically meaningful) to generate keys (not meaningful) via the ftok() function. If you want to generate a random key not shared by any other php instance, then use tempnam() to create a new file, and then ftok it.
Yes – put something in there after you create it. If it was empty in between these 2 steps then it’s new.