Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46114 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47828 invoked from network); 19 Nov 2009 20:18:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2009 20:18:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=matt@bitwarehouse.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=matt@bitwarehouse.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain bitwarehouse.com from 209.85.220.227 cause and error) X-PHP-List-Original-Sender: matt@bitwarehouse.com X-Host-Fingerprint: 209.85.220.227 mail-fx0-f227.google.com Received: from [209.85.220.227] ([209.85.220.227:42420] helo=mail-fx0-f227.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 49/5F-65535-138A50B4 for ; Thu, 19 Nov 2009 15:18:58 -0500 Received: by fxm27 with SMTP id 27so2898141fxm.23 for ; Thu, 19 Nov 2009 12:18:54 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.87.75 with SMTP id x53mr152120wee.13.1258661934552; Thu, 19 Nov 2009 12:18:54 -0800 (PST) Date: Thu, 19 Nov 2009 14:18:54 -0600 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: clarification on maximum string sizes in PHP on 64 bit linux From: matt@bitwarehouse.com (Matt Wirges) Folks, I'm hoping someone can clarify for me the limitations that PHP 5.2/5.3/6.0 is expected to put on the size of strings on 64 bit linux. The php manual documentation for the string type makes the following note about string size: "Note: It is no problem for a string to become very large. PHP imposes no boundary on the size of a string; the only limit is the available memory of the computer on which PHP is running." However, it is clear based on the behavior of PHP 5.2 and 5.3 on 64 bit systems with > 2GB of RAM, that PHP string functions do not behave properly with strings that exceed 2^31 bytes. I filed the now resolved bug #50207 on this matter due to a segfault during in-place concatenation, however the solution now implicitly limits that operation to only strings less than 2^31 bytes in length. Additionally, when strings grow this large, the behaviors of strlen, substr, concatenation, etc. are unreliable. For example, php tries to allocate an impossible amount of memory when concatenating two strings of 2^30 bytes, I presume because the overflowed length of the new string is cast to size_t for allocation: --- Code: --- Result: ./sapi/cli/php -d memory_limit=-1 a2.php Fatal error: Out of memory (allocated 2148270080) (tried to allocate 18446744071562067969 bytes) in /home/matt/tmp/php-src-5.2/a2.php on line 3 ---- So should strings be limited to 2GB on 64 bit systems, is PHP not 64 bit compatible, or are these behaviors that should have bugs filed for them? Thanks, -matt