dsb12300 2019-04-26 13:31
浏览 72

如何确定自身运行的PHP CLI进程数量,跨操作系统?

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).

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 matlab求解平差
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办