I've had this problem for many years. While I was running PHP only on FreeBSD, I used an "insane hack" which never seemed to work perfectly, and in either case was ugly and very specific to FreeBSD.
I see countless examples of Linux/"Unix"-only methods, which are of no value to me. I want every function I code in PHP to be entirely cross-platform, which naturally very much includes Windows. (I don't like any of the existing OSes, and keep hoping that there will be a new system altogether to switch to in the future, which will support PHP or the other way around.)
Is there really no such thing, built into PHP (7.3) itself? I've really searched but found nothing on my own, but it could still be there, hiding in the long list of functions.
My goal is to be able to do this in my application code:
function am_I_already_running()
{
if (num_instances_running(__FILE__) > 1)
return true;
return false;
}
if (am_I_already_running())
exit();
To me, the assumption that Linux is used in certain circles is just as annoying as the assumption that Windows is used. I find the concept of using only code that will run on "all" operating systems to be beautiful. I want to avoid platform-specific stuff at all costs. It doesn't feel "clean" or "proper" when I know that some things will break/not function correctly depending on where I move my code, even if it does end up running primarily on Linux (due to lack of choice).