国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial PHP內(nèi)核(1)內(nèi)存管理

PHP內(nèi)核(1)內(nèi)存管理

Jun 13, 2016 pm 12:28 PM
limit memory php zend

PHP內(nèi)核(一)內(nèi)存管理

本文鏈接:http://www.orlion.ml/tag/php-internal/

一、內(nèi)存管理基礎(chǔ)

用c語言開發(fā)時,開發(fā)者要手動進行內(nèi)存管理。PHP經(jīng)常作為web服務(wù)器的模塊,內(nèi)存管理與預(yù)防內(nèi)存泄露緊密關(guān)聯(lián)。另外PHP可能用于線程環(huán)境中,所以全局變量可能導(dǎo)致競爭情況。此外Zend引擎面對一個十分特殊的使用模式:在一段比較短的時間內(nèi),許多zval結(jié)構(gòu)大小的內(nèi)存塊和其他的小內(nèi)存塊被申請又再被釋放,PHP的內(nèi)存管理也很重視memory_limit(內(nèi)存限制)

為了滿足以上的需求,Zend引擎提供了為了處理請求相關(guān)數(shù)據(jù)提供了一種特殊的內(nèi)存管理器。請求相關(guān)數(shù)據(jù)是指只需要服務(wù)于單個請求,最遲在請求結(jié)束時釋放的數(shù)據(jù)。擴展開發(fā)者主要接觸下表中列出的慣例,雖然一些所提供的便捷功能使用宏實現(xiàn)的,但是本文中會像函數(shù)一樣對待。

如上所述,防止有內(nèi)存泄露并盡可能快的釋放所有內(nèi)存是內(nèi)存管理的重要組成部分。因為安全原因,在請求結(jié)束時,Zend引擎會釋放所有由上面提到的API所分配的內(nèi)存。如果PHP使用--enable-debug配置選項進行構(gòu)建,這將產(chǎn)生一個警告

當(dāng)使用PHP變量時,需要確認變量的內(nèi)存要使用emalloc來分配,并注意引用計數(shù)。

內(nèi)存泄漏檢測僅可以發(fā)現(xiàn)由 emalloc 分配內(nèi)存塊導(dǎo)致的泄漏。為進行深層分析,建議使用內(nèi)存檢測器,如 valgrind 或 libumem 等。要簡化此分析,可在 PHP 啟動時通過設(shè)置環(huán)境變量 USE_ZEND_ALLOC=0 來禁用 PHP 的內(nèi)存管理器。

(以上是PHP官網(wǎng)中文內(nèi)容)

二、數(shù)據(jù)持久化

數(shù)據(jù)持久化意味著任何數(shù)據(jù)預(yù)計比當(dāng)前請求生存時間長,沒有Zend引擎的內(nèi)存管理器非常關(guān)注于請求綁定分配,但是這通常不是實用或者是合適的。持久化內(nèi)存有時需要為了滿足外部類庫的要求,它也是有用的"黑科技"。

持久化內(nèi)存通常用在持久化數(shù)據(jù)庫連接上,雖然實踐起來并不好,但依然是最常使用的特性。

注意:下面所有函數(shù)采取額外的持久化參數(shù)應(yīng)該是false,引擎將用常規(guī)的分配器(emalloc),內(nèi)存不應(yīng)該是?considered persistent(不會翻譯!)。作為持久化的內(nèi)存,系統(tǒng)調(diào)用分配器,正像主要的內(nèi)存API一樣在大多數(shù)情況下它們?nèi)匀徊环祷乜罩羔?/p>

警告:需要注意被分配用來持久化的內(nèi)存不是最優(yōu)化的或者是被Zend引擎跟蹤的,它不被memory_limit所限制,另外,所有通過the hacker創(chuàng)建的變量一定不能被用來持久化內(nèi)存。

(翻譯的真爛!)

1樓tianxintian22
原來是翻譯的,怪不得沒讀懂︿( ̄︶ ̄)︿
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to handle File Uploads securely in PHP? How to handle File Uploads securely in PHP? Jul 08, 2025 am 02:37 AM

To safely handle PHP file uploads, you need to verify the source and type, control the file name and path, set server restrictions, and process media files twice. 1. Verify the upload source to prevent CSRF through token and detect the real MIME type through finfo_file using whitelist control; 2. Rename the file to a random string and determine the extension to store it in a non-Web directory according to the detection type; 3. PHP configuration limits the upload size and temporary directory Nginx/Apache prohibits access to the upload directory; 4. The GD library resaves the pictures to clear potential malicious data.

How Do You Pass Variables by Value vs. by Reference in PHP? How Do You Pass Variables by Value vs. by Reference in PHP? Jul 08, 2025 am 02:42 AM

InPHP,variablesarepassedbyvaluebydefault,meaningfunctionsorassignmentsreceiveacopyofthedata,whilepassingbyreferenceallowsmodificationstoaffecttheoriginalvariable.1.Whenpassingbyvalue,changestothecopydonotimpacttheoriginal,asshownwhenassigning$b=$aorp

How Do Generators Work in PHP? How Do Generators Work in PHP? Jul 11, 2025 am 03:12 AM

AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or

PHP header location ajax call not working PHP header location ajax call not working Jul 10, 2025 pm 01:46 PM

The reason why header('Location:...') in AJAX request is invalid is that the browser will not automatically perform page redirects. Because in the AJAX request, the 302 status code and Location header information returned by the server will be processed as response data, rather than triggering the jump behavior. Solutions are: 1. Return JSON data in PHP and include a jump URL; 2. Check the redirect field in the front-end AJAX callback and jump manually with window.location.href; 3. Ensure that the PHP output is only JSON to avoid parsing failure; 4. To deal with cross-domain problems, you need to set appropriate CORS headers; 5. To prevent cache interference, you can add a timestamp or set cache:f

How to prevent session hijacking in PHP? How to prevent session hijacking in PHP? Jul 11, 2025 am 03:15 AM

To prevent session hijacking in PHP, the following measures need to be taken: 1. Use HTTPS to encrypt the transmission and set session.cookie_secure=1 in php.ini; 2. Set the security cookie attributes, including httponly, secure and samesite; 3. Call session_regenerate_id(true) when the user logs in or permissions change to change to change the SessionID; 4. Limit the Session life cycle, reasonably configure gc_maxlifetime and record the user's activity time; 5. Prohibit exposing the SessionID to the URL, and set session.use_only

How to URL encode a string in PHP with urlencode How to URL encode a string in PHP with urlencode Jul 11, 2025 am 03:22 AM

The urlencode() function is used to encode strings into URL-safe formats, where non-alphanumeric characters (except -, _, and .) are replaced with a percent sign followed by a two-digit hexadecimal number. For example, spaces are converted to signs, exclamation marks are converted to!, and Chinese characters are converted to their UTF-8 encoding form. When using, only the parameter values ??should be encoded, not the entire URL, to avoid damaging the URL structure. For other parts of the URL, such as path segments, the rawurlencode() function should be used, which converts the space to . When processing array parameters, you can use http_build_query() to automatically encode, or manually call urlencode() on each value to ensure safe transfer of data. just

How to access a character in a string by index in PHP How to access a character in a string by index in PHP Jul 12, 2025 am 03:15 AM

In PHP, you can use square brackets or curly braces to obtain string specific index characters, but square brackets are recommended; the index starts from 0, and the access outside the range returns a null value and cannot be assigned a value; mb_substr is required to handle multi-byte characters. For example: $str="hello";echo$str[0]; output h; and Chinese characters such as mb_substr($str,1,1) need to obtain the correct result; in actual applications, the length of the string should be checked before looping, dynamic strings need to be verified for validity, and multilingual projects recommend using multi-byte security functions uniformly.

PHP get the first N characters of a string PHP get the first N characters of a string Jul 11, 2025 am 03:17 AM

You can use substr() or mb_substr() to get the first N characters in PHP. The specific steps are as follows: 1. Use substr($string,0,N) to intercept the first N characters, which is suitable for ASCII characters and is simple and efficient; 2. When processing multi-byte characters (such as Chinese), mb_substr($string,0,N,'UTF-8'), and ensure that mbstring extension is enabled; 3. If the string contains HTML or whitespace characters, you should first use strip_tags() to remove the tags and trim() to clean the spaces, and then intercept them to ensure the results are clean.

See all articles