久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

增加 PHP memory_limit.什么時候會變得瘋狂?

Increasing PHP memory_limit. At what point does it become insane?(增加 PHP memory_limit.什么時候會變得瘋狂?)
本文介紹了增加 PHP memory_limit.什么時候會變得瘋狂?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

在我目前正在研究的系統(tǒng)中,有一個進(jìn)程將大量數(shù)據(jù)加載到數(shù)組中以進(jìn)行排序/聚合/任何操作.我知道這個過程需要優(yōu)化內(nèi)存使用,但在短期內(nèi)它只需要工作.

In a system I am currently working on, there is one process that loads large amount of data into an array for sorting/aggregating/whatever. I know this process needs optimising for memory usage, but in the short term it just needs to work.

鑒于加載到數(shù)組中的數(shù)據(jù)量,我們不斷達(dá)到內(nèi)存限制.它已經(jīng)增加了好幾倍,我想知道是否有一點增加它通常會變成一個壞主意?還是是機(jī)器有多少內(nèi)存的問題?

Given the amount of data loaded into the array, we keep hitting the memory limit. It has been increased several times, and I am wondering is there a point where increasing it becomes generally a bad idea? or is it only a matter of how much RAM the machine has?

機(jī)器有 2GB 的 RAM,memory_limit 目前設(shè)置為 1.5GB.我們可以輕松地為機(jī)器添加更多 RAM(無論如何都會這樣做).

The machine has 2GB of RAM and the memory_limit is currently set at 1.5GB. We can easily add more RAM to the machine (and will anyway).

其他人遇到過這種問題嗎?以及解決方案是什么?

Have others encountered this kind of issue? and what were the solutions?

推薦答案

PHP 作為 Apache 模塊運行到服務(wù)器網(wǎng)頁的 memory_limit 配置必須考慮到您可以有多少 Apache 進(jìn)程同時在機(jī)器上 - 請參閱 Apache 的 MaxClients 配置選項.

The configuration for the memory_limit of PHP running as an Apache module to server webpages has to take into consideration how many Apache process you can have at the same time on the machine -- see the MaxClients configuration option for Apache.

如果 MaxClients 是 100 并且您有 2,000 MB 的 RAM,一個非常快速的計算將表明您不應(yīng)使用超過 20 MB *(因為 20 MB * 100 個客戶端 = 2 GB 或 RAM,即您的服務(wù)器擁有的總內(nèi)存量)* 用于 memory_limit 值.

If MaxClients is 100 and you have 2,000 MB of RAM, a very quick calculation will show that you should not use more than 20 MB *(because 20 MB * 100 clients = 2 GB or RAM, ie the total amount of memory your server has)* for the memory_limit value.

這還沒有考慮到可能在同一臺服務(wù)器上運行其他東西,比如 MySQL、系統(tǒng)本身,......而且 Apache 可能已經(jīng)在為自己使用一些內(nèi)存.

And this is without considering that there are probably other things running on the same server, like MySQL, the system itself, ... And that Apache is probably already using some memory for itself.

當(dāng)然,這也是一個最壞情況",即考慮到每個 PHP 頁面都在使用它可以使用的最大內(nèi)存量.

Or course, this is also a "worst case scenario", that considers that each PHP page is using the maximum amount of memory it can.


在您的情況下,如果您只需要為一項工作提供如此大的內(nèi)存,我不會為作為 Apache 模塊運行的 P?P 增加 memory_limit.

相反,我會從命令行(或通過 cron 作業(yè)) 啟動該作業(yè),并在這種且唯一的情況下指定更高的 memory_limit.

Instead, I would launch that job from command-line (or via a cron job), and specify a higher memory_limit specificaly in this one and only case.

這可以通過 php 的 -d 選項來完成,例如:

This can be done with the -d option of php, like :

$ php -d memory_limit=1GB temp.php
string(3) "1GB"

考慮到在這種情況下,temp.php 僅包含:

Considering, in this case, that temp.php only contains :

var_dump(ini_get('memory_limit'));

在我看來,這比為 Apache 增加 PHP 模塊的 memory_limit 更安全 -- 當(dāng)我有一個大型數(shù)據(jù)集或一些我無法優(yōu)化或分頁的非常重的東西時,我通常會這樣做.

In my opinion, this is way safer than increasing the memory_limit for the PHP module for Apache -- and it's what I usually do when I have a large dataset, or some really heavy stuff I cannot optimize or paginate.


如果您需要為 PHP CLI 執(zhí)行定義多個值,您還可以通過 -c 選項告訴它使用另一個配置文件,而不是默認(rèn)的 php.ini:


If you need to define several values for the PHP CLI execution, you can also tell it to use another configuration file, instead of the default php.ini, with the -c option :

php -c /etc/phpcli.ini temp.php

那樣,你有:

  • /etc/php.ini for Apache,低memory_limit,低max_execution_time,...
  • /etc/phpcli.ini 用于從命令行運行的批處理,幾乎沒有限制
  • /etc/php.ini for Apache, with low memory_limit, low max_execution_time, ...
  • and /etc/phpcli.ini for batches run from command-line, with virtually no limit

這可確保您的批處理能夠運行——并且您的網(wǎng)站仍然具有安全性(memory_limitmax_execution_time 是安全措施)

This ensures your batches will be able to run -- and you'll still have security for your website (memory_limit and max_execution_time being security measures)


盡管如此,如果您有時間優(yōu)化您的腳本,您應(yīng)該:例如,在您必須處理大量數(shù)據(jù)的情況下,分頁是必不可少的 ;-)


Still, if you have the time to optimize your script, you should ; for instance, in that kind of situation where you have to deal with lots of data, pagination is a must-have ;-)

這篇關(guān)于增加 PHP memory_limit.什么時候會變得瘋狂?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 国产婷婷综合 | 欧美爱爱视频网站 | 日本亚洲欧美 | 久久伊人精品一区二区三区 | 欧美激情一区二区三区 | 久久久精品 | 国产综合久久久久久鬼色 | 国产精品一区在线 | 免费欧美| 91视视频在线观看入口直接观看 | 日本成人福利视频 | 国产乱码精品一区二区三区五月婷 | 91精品国产乱码麻豆白嫩 | 久久国产精品一区二区 | 一久久久 | 国产乱码一区 | 激情毛片| 国产欧美一级二级三级在线视频 | 精品中文在线 | 美女黄18岁以下禁止观看 | 91精品国产日韩91久久久久久 | 瑞克和莫蒂第五季在线观看 | 欧美精品一区二区三区蜜桃视频 | 成人精品在线视频 | 欧美啊v在线观看 | 一区二区三区高清 | 欧美日韩国产在线观看 | 欧美在线视频一区 | 欧美精品一区二区三区蜜桃视频 | 精产国产伦理一二三区 | 99亚洲精品| 性高湖久久久久久久久aaaaa | 天天射色综合 | 九九热热九九 | 日韩精品在线免费 | 日韩成人国产 | 精品成人免费一区二区在线播放 | 在线播放国产一区二区三区 | 日韩中字幕| 国产丝袜一区二区三区免费视频 | 精品国产不卡一区二区三区 |