LMLPHP后院

PHP 内存泄露重现 include 匿名函数技术

maybe yes 发表于 2022-05-01 10:11

这个坑估计全网没有人踩过,这篇应该是公开出来的第一篇,很多人就算是踩了这个坑,也不一定会触发,即使是触发了,也不一定发现的了。

这个是 include 或者是 require 对于匿名函数的内存泄露大坑。

很多市面上的 PHP 教程都说 include require 相当于把代码复制到那个位置,从这个代码示例验证来看,其实不是这样的!

$i=0;
while (true) {
        if ($i%1000 == 0) {
                echo memory_get_usage()."\n";
                sleep(1);
        }
        $i++;
        $b = 'b';
        $render_func = function($d) use ($b) {
                $u = 1;
                //test3.php $x = function(){};
                require 'test3.php';
        };
        $render_func($i);
}
return;

How to Increase Number of Open Files Limit in Linux技术

maybe yes 发表于 2022-04-17 17:43

发现这个比较难搞,中文的网页没有一个是对的。

Find Linux Open File Limit
The value is stored in:

# cat /proc/sys/fs/file-max

818354
The number you will see, shows the number of files that a user can have opened per login session. The result might be different depending on your system.

For example on a CentOS server of mine, the limit was set to 818354, while on Ubuntu server that I run at home the default limit was set to 176772.

If you want to see the hard and soft limits, you can use the following commands:

Check Hard Limit in Linux
# ulimit -Hn

4096
Check Soft Limits in Linux
# ulimit -Sn

1024
To see the hard and soft values for different users, you can simply switch user with “su” to the user which limits you want to check.

For example:

# su marin
$ ulimit -Sn

1024
$ ulimit -Hn

4096
How to Check System wide File Descriptors Limits in Linux
If you are running a server, some of your applications may require higher limits for opened file descriptors. A good example for such are MySQL/MariaDB services or Apache web server.

You can increase the limit of opened files in Linux by editing the kernel directive fs.file-max. For that purpose, you can use the sysctl utility.

Sysctl is used to configure kernel parameters at runtime.

For example, to increase open file limit to 500000, you can use the following command as root:

# sysctl -w fs.file-max=500000
You can check the current value for opened files with the following command:

$ cat /proc/sys/fs/file-max
With the above command the changes you have made will only remain active until the next reboot. If you wish to apply them permanently, you will have to edit the following file:

# vi /etc/sysctl.conf
Add the following line:

fs.file-max=500000
Of course, you can change the number per your needs. To verify the changes again use:

# cat /proc/sys/fs/file-max
Users will need to logout and login again for the changes to take effect. If you want to apply the limit immediately, you can use the following command:

# sysctl -p
Set User Level Open File limits in Linux
The above examples, showed how to set global limits, but you may want to apply limits per user basis. For that purpose, as user root, you will need to edit the following file:

# vi /etc/security/limits.conf
If you are a Linux administrator, I suggest you that you become very familiar with that file and what you can do to it. Read all of the comments in it as it provides great flexibility in terms of managing system resources by limiting users/groups on different levels.

The lines that you should add take the following parameters:

<domain>        <type>  <item>  <value>
Here is an example of setting a soft and hard limits for user marin:

## Example hard limit for max opened files
marin        hard nofile 4096
## Example soft limit for max opened files
marin        soft nofile 1024
Final thoughts
This brief article showed you a basic example of how you can check and configure global and user level limits for maximum number of opened files.

While we just scratched the surface, I highly encourage you to have a more detailed look and read regarding /etc/sysctl.conf and /etc/security/limits.conf and learn how to use them. They will be of great help for you one day.

记录一个问题技术

maybe yes 发表于 2022-04-16 17:58

记录一个问题,有没有好的解决方案!

假设 archive.tgz 大小约 2M,里面有 1000 个小文件,其中一个文件名字为 a.txt,我们为了拿到 a.txt,则需要执行下面的命令!

tar zxOf archive.tgz a.txt

现在的问题是,上面的命令存在性能问题,耗时有时候会高达 20s。如何加快这个速度呢?

最好的解决问题的方法,我猜想,因该是不压缩,只打包!

chrome 不能录音:Uncaught TypeError: Cannot read property ‘getUserMedia‘ of undefined技术

maybe yes 发表于 2022-04-08 10:39

记录一下,虽然这个问题我没有问题。

chrome 浏览器不能录音:Uncaught TypeError: Cannot read property ‘getUserMedia‘ of undefined 解决方法

打不开浏览器录音功能的问题解决方案,在浏览器的地址栏里输入 chrome://flags/#unsafely-treat-insecure-origin-as-secure 并回车、然后改成 Enabled。

貌似,我按照上面的试了,依然不行,其实不是上面的原因啦,无关痛痒的修改!

写这篇文章,是最近做了个 WEB 在线视频聊天,发现浏览器的行为特别的在意 https,如果不是 https 是无法开启摄像头和录音的,所以,在本地开发很难测试啦!

referer 只有域名的问题技术

maybe yes 发表于 2022-04-05 11:15

再次骂 Google Chrome,总是瞎鸡吧乱改规则。

Chrome 真是个蛋疼的浏览器,总是乱改规则,前面遇到过 post 不携带 Cookie 问题,现在又遇到了不携带 Referer 的问题。感觉这帮制定规则的人脑子🧠有问题,你如果是为了安全,可以由网站主来决定,我如果不想携带,那我做个设置,你来瞎搞什么啊,Javascript 本身是可以获取的,我如果要传,不就是麻烦一点吗,一样可以做得到。这个事情困扰了我好久,发现统计的路径总是只有域名,我开始还以为是跳转出现的问题,一直没有时间去查个究竟,最近发现实在是奇怪,越来越奇怪,才发现,原来是 Chrome 85 惹的祸啊。

最近还在想 http_accept_language 的格式问题,作为代码工作者一定会发现,被它这个字段的规则弄糊涂了,实在是费解啊。http_accept_language 如果按 ; 分号分割,感觉难理解,如果按照 , 逗号分隔,也不是那么容易理解。最有发现确实是 , 逗号分隔,按照有点常识的人来讲,逗号 , 怎么可以用来做分隔呢,分号 ; 才更合理啊。现在真的是脱节了,指定规则的人经验非常不丰富,但是规则一旦确定,大家只能遵守!

2022-05-22 13:27:18 1653197238 0.025354