PHP not recognizing memory_limit changes - php

I was hoping someone could help me out. I cannot get the memory_limit config setting to work on my PHP laravel install. Even something as simple as php artisan --help gives me a memory exhausted error.
I've tried modifying all my php.ini files, and specifying the config via the -d flag , but none of them seem to work. I feel like there's something else I'm missing?
Here's some shell output from my setup, please let me know if there's anything else you'd like to see.
vagrant#precise64:/vagrant/www$ uname -a
Linux precise64 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
vagrant#precise64:/vagrant/www$ php --version
PHP 5.4.33-2+deb.sury.org~precise+1 (cli) (built: Sep 25 2014 09:06:25)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
vagrant#precise64:/vagrant/www$ php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
vagrant#precise64:/vagrant/www$ php -i | grep memory_limit
memory_limit => -1 => -1
vagrant#precise64:/vagrant/www$ grep -r memory_limit /etc/php5/
/etc/php5/cli/php.ini:memory_limit = -1
/etc/php5/fpm/php.ini.ucf-dist:memory_limit = -1
/etc/php5/fpm/php.ini:memory_limit = -1
/etc/php5/fpm/pool.d/www.conf:php_admin_value[memory_limit] = -1
vagrant#precise64:/vagrant/www$ grep -r safe_mode /etc/php5/ | grep =
/etc/php5/cli/php.ini:sql.safe_mode = Off
/etc/php5/fpm/php.ini.ucf-dist:sql.safe_mode = Off
/etc/php5/fpm/php.ini:safe_mode = Off
/etc/php5/fpm/php.ini:safe_mode_gid = Off
/etc/php5/fpm/php.ini:safe_mode_include_dir =
/etc/php5/fpm/php.ini:safe_mode_exec_dir =
/etc/php5/fpm/php.ini:safe_mode_allowed_env_vars = PHP_
/etc/php5/fpm/php.ini:safe_mode_protected_env_vars = LD_LIBRARY_PATH
/etc/php5/fpm/php.ini:sql.safe_mode = Off
vagrant#precise64:/vagrant/www$ php artisan --help
PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 3072 bytes) in /vagrant/www/app/controllers/TemplateController.php on line 44
Thanks so much in advance, I really have no idea what could be wrong.

This ended up being a weird problem with my routes.php from within Laravel. I had two controllers (WebhookController and TemplateController) specified as Route::controllers, and TemplateController again specified as a Route::resource.
This ended up causing the memory exhaustion errors for reasons I still can't figure out, but that's beside the point.
The fix was to manually specify the controller routes and not use Route::controller at all within my routes.php.

Related

memory_get_usage seems inaccurate, how can I further diagnose a memory leak in PHP?

I'm seeing my long running php processes utilize significant amounts of memory, and it grows very quickly. After about a day, I saw the following:
# pmap <pid>
000000000091c000 588K rw--- /usr/bin/php
00000000009af000 108K rw--- [ anon ]
00000000013ab000 256948K rw--- [ anon ]
00007f9ed0000000 132K rw--- [ anon ]
...
00007f9edcaa6000 8K rw--- /usr/lib64/php/modules/curl.so
00007f9edcaa8000 103580K r---- /usr/lib/locale/locale-archive
...
total 629312K
# cat /proc/<pid>/status
Name: php
State: S (sleeping)
...
VmHWM: 268920 kB
VmRSS: 268920 kB
VmData: 334368 kB
VmStk: 136 kB
VmExe: 3188 kB
VmLib: 22752 kB
VmPTE: 912 kB
VmSwap: 0 kB
Threads: 1
...
Mems_allowed: 00000000,00000001
Mems_allowed_list: 0
voluntary_ctxt_switches: 11902137
ps aux
0.5 4.3 694124 333864 ? S Jan21 8:11 php
top
PR NI VIRT RES SHR S %CPU %MEM TIME+ CODE DATA COMMAND
20 0 677m 326m 9100 S 0.0 4.4 8:11.56 3188 390m php
but, memory_get_usage(true) consistently returns:
1835008
There seems to be a memory leak, but how can I diagnose the cause, and reduce it? I've tried to utilize tools such as this, but similar to memory_get_usage, it doesn't notice any additional memory usage
I've also tried:
# strace -p -e trace=memory
but all I see are brk() calls, like so:
brk(0) = 0x14f6f000
brk(0x14f90000) = 0x14f90000
I'm on version 5.4.27:
# php --version
PHP 5.4.27 (cli) (built: Apr 23 2014 23:34:13)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
You can compile PHP on your own using the --enable-debug configure option. If you execute a php cli script compiled that way you'll get a detailed explanation about detected memory leaks - if there are any.
However, the fact that memory_get_usage() returns a constant value looks weird. Can you reduce the problem to a single script? (Or show your script?) Can you nail it down to certain PHP extension? Which version of PHP are you using?

PHP vld shows file output instead of opcode

I'm trying to use vld to view opcode of a php file
prep
I've installed vld with:
pecl install channel://pecl.php.net/vld-0.12.0
To get familiar with VLD, I'm trying to compare to php files (echo1 and echo2)
echo1.php
<?php
echo "Hello"." "."World";
echo2.php
<?php
echo "Hello"," ","World";
phpinfo() shows that vld seems to be enabled:
vld support enabled
Directive Local Value Master Value
vld.active 0 0
vld.col_sep
vld.dump_paths 1 1
vld.execute 1 1
vld.format 0 0
vld.save_dir /tmp /tmp
vld.save_paths 0 0
vld.skip_append 0 0
vld.skip_prepend 0 0
vld.verbosity 1 1
problem
running php files shows output instead of opcode
# php -dvld.active=1 -f echo1.php
Hello World
# php -dvld.active=1 -dvld.execute=0 -f echo1.php
Hello World
# php -dvld.active=1 -f echo2.php
Hello World
# php -dvld.active=1 -dvld.execute=0 -f echo2.php
Hello World
Obviously I'm missing something :)
versions running
php version
# php -v
PHP 5.4.4-14+deb7u14 (cli) (built: Aug 21 2014 08:36:44)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
Running Debian in Virtualbox with Apache 2.2.22
After updating to PHP 5.6.2 I gave it another go and it is running :)
php version
# php -v
PHP 5.6.2 (cli) (built: Oct 17 2014 07:22:10)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
install pear
yum install php56w-pear
installing vld
pecl install vld
add extension to /etc/php.ini (or in file in /etc/php.d/__.ini)
#/etc/php.d/vld.ini
extension=vld.so
restart httpd service and test again (fingers crossed)
# php -dvld.active=1 -f echo1.php
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename: /var/www/html/echo1.php
function name: (null)
number of ops: 4
compiled vars: none
line #* E I O op fetch ext return operands
-------------------------------------------------------------------------------------
2 0 E > CONCAT ~0 'Hello', '+'
1 CONCAT ~1 ~0, 'World'
2 ECHO ~1
3 3 > RETURN 1
branch: # 0; line: 2- 3; sop: 0; eop: 3; out1: -2
path #1: 0,
Hello World
Boom Baby!
I don't know why, but it is working as expected :)
Now the OPCODE adventures can begin (also a love story)
You might be add extension.so to wrong php.ini file
You might be add the extension to php.ini that use by your webserver instead of cli version
What you can do is run locate php.ini, and choose the cli version of php.ini and add extension.so to that file
Normally cli version of php.ini located at /etc/php5/cli/php.ini
Dont forget to restart your console too

redeclare class condition_info

I upgrade my moodle from 2.6.4 to 2.7.1. After upgrading I've got blank (white) screen. Then I turn on debug display in config.php
$CFG->debug = 32767;
$CFG->debugdisplay = true;
After that I receive an error: Fatal error: Cannot redeclare class condition_info in /home/moodle/public_html/lib/conditionlib.php on line 105.
Then I search and found that might be a problem with opcache (https://tracker.moodle.org/browse/MDL-45797). So I follow this doc - http://docs.moodle.org/27/en/admin/environment/php_setting/opcache.enable and enable opcache in php.ini:
[opcache]
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 4000
opcache.revalidate_freq = 60
; Required for Moodle
opcache.use_cwd = 1
opcache.validate_timestamps = 1
opcache.save_comments = 1
opcache.enable_file_override = 0
; If something does not work in Moodle
;opcache.revalidate_path = 1 ; May fix problems with include paths
;opcache.mmap_base = 0x20000000 ; (Windows only) fix OPcache crashes with event id 487
; Experimental for Moodle 2.6 and later
;opcache.fast_shutdown = 1
;opcache.enable_cli = 1 ; Speeds up CLI cron
;opcache.load_comments = 0 ; May lower memory use, might not be compatible with add-ons and other apps.
Reload apache and it still doesn't work. I also try to comment out part ; If something does not work in Moodle and error still occurs. Any idea what might be wrong?
I also read that might be a problem with themes. Before I upgrade I switch theme to Clean which is default theme in 2.7.
I have ubuntu 14.04 with PHP 5.5.9-1ubuntu4.3 (cli) (built: Jul 7 2014 16:36:58)
This might be a bug or an incompatibility with the opcache system.
i would suggest to turn the opcache off: opcache.enable = 0. The opcache is only good, if everything works and you want to gain some additional performance.
restart PHP
restart Apache
Finally try one of these downloads:
2.7 - https://github.com/moodle/moodle/archive/v2.7.1.tar.gz
master [latest] - https://github.com/moodle/moodle/archive/master.zip
If the problem persists: please open a new bug report over at moodle and reference the report you found. it is clearly related.

PHP fopen() returns NULL, always

I'm attempting to open a file for parsing (a binary file), however no matter what fopen() is always returning NULL.
I've ruled out nearly everything to the point where I have a test script with simply:
<?php
$idx = fopen('/usr/home/username/web/appname/dev/www/debug/18194001.idx','r');
trigger_error(var_export($idx,true));
exit();
The output from trigger_error(var_export()); is:
[31-Mar-2013 16:30:34 UTC] PHP Notice: NULL in /usr/home/username/web/appname/dev/www/debug/ajax.idx.php on line 3
No matter what flags I specify for the second fopen() option, I get the same result.
Now, the obvious question is whether or not the file exists, and do I have permissions to read it? The answer to both of those is yes. I've used the relative path and absolute path, both read the file correct. file_get_contents() also reads the file with no issues.
is_readable() and file_exists() both return true
The output of ls -lah for that file is:
-rwxrwxrwx 1 username username 2.0K Mar 30 15:02 18194001.idx
Where 'username' matches the username the web server process and PHP (lighttpd and php-fpm) are running under. The parent directory also has read/read/read rights for user/group/all.
I've tried other files, and I've noticed pretty much anything I throw at fopen is returning a NULL value.
Help?
PHP info:
PHP 5.4.6 (cli) (built: Oct 10 2012 10:43:19)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with XCache v2.0.1, Copyright (c) 2005-2012, by mOo
Lighttpd info:
lighttpd/1.4.31 (ssl) - a light and fast webserver
Build-Date: Sep 7 2012 15:38:20
OS:
FreeBSD hostname.hostname.hostname 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Thu Feb 17 02:41:51 UTC 2011 root#mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
You cannot meaningfully var_export a fopened resource, you can however var_dump it:
$ php -r 'var_export(fopen("/tmp/a","w+"));'
NULL
$ php -r 'var_dump(fopen("/tmp/a","w+"));'
resource(5) of type (stream)
... because var_export() is meant to 'restore' a variable in PHP script, and resources require more setup then possible in instantiating a simple variable. If you want to know whether the fopen succeeded, just check it is not false.
$ php -r 'var_export(fopen("/this/does/not/exist","w+"));'
... some errors...
false
In other words, the fact you get NULL from a var_export means the fopen actually was successful.

Lighttpd + PHP + FCGI

I have a problem with Lighttpd, PHP and CGI.
I use OpenSUSE.10.
I have builded lighttpd (version 1.4.23) and php (version 5.3.0).
This is lighttpd build command lines:
./configure --prefix=/home/gosh/Desktop/web_server/lighttpd_native_installed --without-zlib --enable-ssl --enable-openssl --with-openssl=/home/gosh/Desktop/web_server/openssl_native_installed --with-openssl-includes=/home/gosh/Desktop/web_server/openssl_native_installed/include --with-openssl-libs=/home/gosh/Desktop/web_server/openssl_native_installed/lib --without-pcre --with-zlib --without-bzip2
make
make install
This is php build command lines:
./configure --prefix=/home/gosh/Desktop/web_server/php_native_installed --without-iconv --disable-libxml --disable-dom --disable-simplexml --disable-xml --disable-xmlreader --disable-xmlwriter --without-pear --enable-fastcgi --enable-force-cgi-redirect
make
make install
This is php, php-cgi -v:
gosh#suse:~/Desktop/web_server> /home/gosh/Desktop/web_server/php_native_installed/bin/php -v
PHP 5.3.0 (cli) (built: Aug 30 2009 03:56:22)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
gosh#suse:~/Desktop/web_server> /home/gosh/Desktop/web_server/php_native_installed/bin/php-cgi -v
PHP 5.3.0 (cgi-fcgi) (built: Aug 30 2009 03:55:55)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
gosh#suse:~/Desktop/web_server>
This is lighttpd.conf:
server.document-root = "/home/gosh/Desktop/web_server"
server.port = 81
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".png" => "image/png"
)
index-file.names = ( "index.php" )
server.modules = (
"mod_fastcgi",
"mod_accesslog"
)
accesslog.filename = "/home/gosh/Desktop/web_server/lighttpd_access0.log"
server.accesslog = "/home/gosh/Desktop/web_server/lighttpd_access000.log"
fastcgi.debug = 1
fastcgi.server = (
".php" =>
((
"bin-path" => "/home/gosh/Desktop/web_server/php_native_installed/php-cgi -c /home/gosh/Desktop/web_server/php.ini",
"socket" => "php.socket"
)),
".html" =>
((
"bin-path" => "/home/gosh/Desktop/web_server/php_native_installed/php-cgi -c /home/gosh/Desktop/web_server/php.ini",
"socket" => "php.socket"
))
)
$SERVER["socket"] == "127.0.0.1:443" {
server.document-root = "/home/gosh/Desktop/web_server"
ssl.engine = "enable"
ssl.pemfile = "/home/gosh/Desktop/web_server/lighttpd.pem"
server.errorlog = "/home/gosh/Desktop/web_server/lighttpd_error.log"
server.accesslog = "/home/gosh/Desktop/web_server/lighttpd_access1.log"
accesslog.filename = "/home/gosh/Desktop/web_server/lighttpd_access2.log"
}
This is command line to start lighttpd:
sudo /home/gosh/Desktop/web_server/lighttpd_native_installed/sbin/lighttpd -f /home/gosh/Desktop/web_server/lighttpd.conf -m /home/gosh/Desktop/web_server/lighttpd_native_installed/lib
And, finally, lighttpd creates lighttpd_error.log:
2009-08-30 04:44:01: (log.c.172) server started
2009-08-30 04:44:01: (mod_fastcgi.c.1365) --- fastcgi spawning local
proc: /home/gosh/Desktop/web_server/php_native_installed/php-cgi -c /home/gosh/Desktop/web_server/php.ini
port: 0
socket php.socket
min-procs: 4
max-procs: 4
2009-08-30 04:44:01: (mod_fastcgi.c.1390) --- fastcgi spawning
port: 0
socket php.socket
current: 0 / 4
2009-08-30 04:44:01: (mod_fastcgi.c.1087) the fastcgi-backend /home/gosh/Desktop/web_server/php_native_installed/php-cgi -c /home/gosh/Desktop/web_server/php.ini failed to start:
2009-08-30 04:44:01: (mod_fastcgi.c.1091) child exited with status 2 /home/gosh/Desktop/web_server/php_native_installed/php-cgi -c /home/gosh/Desktop/web_server/php.ini
2009-08-30 04:44:01: (mod_fastcgi.c.1094) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version.
If this is PHP on Gentoo, add 'fastcgi' to the USE flags.
2009-08-30 04:44:01: (mod_fastcgi.c.1398) [ERROR]: spawning fcgi failed.
2009-08-30 04:44:01: (server.c.928) Configuration of plugins failed. Going down.
My questionis are:
1) has anybody successful experience in launching lighttpd + PHP + FastCGI on Ubuntu or OpenSUSE?
2) why spawning fcgi failed?
I.e. I want to use such index.php to test my web-server:
<? php
phpinfo();
?>
P.S.:
If I remove
$SERVER["socket"] == "127.0.0.1:443" {
server.document-root = "/home/gosh/Desktop/web_server"
ssl.engine = "enable"
ssl.pemfile = "/home/gosh/Desktop/web_server/lighttpd.pem"
server.errorlog = "/home/gosh/Desktop/web_server/lighttpd_error.log"
server.accesslog = "/home/gosh/Desktop/web_server/lighttpd_access1.log"
accesslog.filename = "/home/gosh/Desktop/web_server/lighttpd_access2.log"
}
from lighttpd.conf, lighttpd successfully starts and Firefox displays index.html (but not index.php):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Yabaaa!!!</title>
</head>
<body>
HELLO!!!
</body>
</html>
Update:
Thanks for the responses.
lighttpd_error.log exactly says that there is a problem with FCGI and PHP interpreter.
Yes, backports are available ion SUSE or Ubuntu, but they do NOT work too.
I think it is the OS problem.
I have embedded device:
CPU: AMD AU1000 (MIPS platform, not x86)
RAM: 64 MB
HDD: 120 GB
LAN: ethernet controller
Cross compiler to buils apps for this device:
mipsel-linux-gcc
So, I have builded Lighttpd and php for MIPS target, copied them to this device and... server started to work normally. I could see index.php from Mozilla!
I do not know why Lighttpd+PHP does not work on PC.
DECISION: I score on the problem.
If I remove
$SERVER["socket"] == "127.0.0.1:443" {
server.document-root = "/home/gosh/Desktop/web_server"
ssl.engine = "enable"
ssl.pemfile = "/home/gosh/Desktop/web_server/lighttpd.pem"
server.errorlog = "/home/gosh/Desktop/web_server/lighttpd_error.log"
server.accesslog = "/home/gosh/Desktop/web_server/lighttpd_access1.log"
accesslog.filename = "/home/gosh/Desktop/web_server/lighttpd_access2.log"
}
from lighttpd.conf, lighttpd
successfully starts and Firefox
displays index.html
This might be a different problem, here only concerning SSL and Logfiles.
Do these Logfiles exist?
Where's the information about your key-file for SSL?
I'd generally prefer the use of prebuilt-packages. Are there no backports available for SuSE or Ubuntu?
not sure, but most installation guides say that u should add this at the end of you php.ini
cgi.fix_pathinfo = 1
On ubuntu i have notice that the path setup for the php-cgi binary does not use the real binary name, ubuntu install php5-cgi were as the default configuration trys to point to php-cgi hence you get the above error. It had me guessing for a few minutes myself.

Categories