dongya9904 2017-05-12 06:05
浏览 136
已采纳

Localhost不断报告:PHP致命错误:允许的内存大小为262144字节耗尽(试图分配704384字节)

I've got XAMPP running on my local Windows machine to process some simple text files using PHP. It's a fresh install so there's no history of issues prior.

I get the following error:

PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 704384 bytes)

I thought the solution would be pretty easy. I've tried increasing the memory size to 256M (not 256MB!), I've also tried the bytes version of it (268435456). There was only php.ini in the C:\xampp\php folder, there's nothing in the apache\bin regarding php.ini

Also tried setting the memory manually in the script itself using

ini_set('memory_limit','256M');

With no luck. The task itself is very basic - reading in a 640KB file.

Any ideas on what I else I can try?

  • 写回答

1条回答 默认 最新

  • dongqiuxu2270 2017-05-12 06:54
    关注
    ini_set('memory_limit', '256M');
    

    or

    php.ini  =>  memory_limit = 256M
    

    or

    php_value memory_limit 256M
    

    PHP's config can be set in multiple places:

    1. master system php.ini (usually in /etc somewhere)
    2. somewhere in Apache's configuration (httpd.conf or a per-site .conf file, via php_value)
    3. CLI & CGI can have a different php.ini (use the command php -i | grep memory_limit to check the CLI conf)
    4. local .htaccess files (also php_value)

    Also note that PHP generally has different .ini files for command-line and webserver-based operation. Checking phpinfo() from the command line will report different values than if you'd run it in a web-based script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?