PHP exec()对内存的使用 [英] PHP exec() use of memory

查看:137
本文介绍了PHP exec()对内存的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到确切的答案.

I can't seem to find a definitive answer for this one.

在PHP中使用exec()调用shell命令时,shell命令使用的内存是否计入PHP脚本给出的内存限制?

When invoking a shell command using exec() from PHP, does the memory that shell command uses count towards the memory limit that the PHP script is given?

我意识到,如果该命令生成大量输出,并且该输出在exec()$ouput(第二个)参数中捕获,则返回的数据可能会破坏PHP的内存限制.但是,假设所有输出都发送到一个文件,如果exec()命令需要运行128M内存,那么一个内存限制为64M的PHP脚本应该能够运行它吗?

I realise that if the command generates a lot of output, and that output is captured in the $ouput (second) parameter of exec(), then that returned data could blow the PHP memory limit. However, assuming all output is sent to a file, if the exec() command requires 128M of memory to run, should a PHP script with a limit of 64M of memory be able to run it?

<?php
exec('command_using_128M_memory >/dev/null 2>&1');

我假设PHP5.3 +

I'm assuming PHP5.3+

推荐答案

exec()命令不直接计入PHP,因为该过程不是在PHP进程内单独执行的.话虽如此,如果您在命令中使用任何输出变量,它们将计入限制.

The exec() command does not directly count towards the PHP since the process is executed separately not from within the PHP Process. Having said that if you use any output variable with the command they would count towards the limit.

因此,如果您有一个产生大量详细日志记录的文件,并且正在捕获该日志记录,则该文件将计入内存限制.

So if you had a file which produced a lot of verbose logging, and you were capturing that logging it would count towards the memory limit.

这篇关于PHP exec()对内存的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆