I have changed php.ini's some value in php.ini file and also through php script like,
ini_set('upload_max_filesize', '10M');
ini_set('POST_MAX_SIZE', '10MB');
but when I am running phpinfo() it doesn't shows the updated value.
It shows
upload_max_filesize = 2M
I am wondering how it is possible??
Do you have access to your Apache configuration ?
Maybe theses parameters are overridden in the virtual host of the Apache configuration via php_admin_value. If this is the case, then you won't be able to change this value in the php script itself.
Also, check the following post : Changing upload_max_filesize on PHP
Good luck with that.
Firstly, it is very common for your environment to contain several php.ini files, where the one you're editing is not actually being used. Check php_info() output for the path to the loaded configuration file to double check.
If it's definitely correct, restart your web server and double-check it's still not loading.
If you still got no luck, have a look at the return values for ini_set():
if(ini_set('upload_max_filesize', '10M') === FALSE ||
ini_set('POST_MAX_SIZE', '10MB') === FALSE)
{
echo "Failed to set a configuration parameter.";
} else {
// These functions returned strings containing the old value.
}
Let us know what the above returns for you.
Related
It might seem a stupid question, but I'm already trying since one hour to figure it out without success.
As stated in title, I'm actually unable to change memory_limit directive in PHP 7.1.15 but only for php-fpm. In fact if I execute php -i | grep memory_limit in terminal I can see the correct value memory_limit => -1 => -1.
What I tried so far:
Setting memory_limit in php.ini
Using ini_set('memory_limit', -1); directly in PHP script
I also tried to disable all loaded extensions cause I thought maybe one of them is overwriting that setting, but didn't work.
Also consider that edited php.ini file is the correct one since I was able to change max_execution_time without any problem.
So how this code
ini_set('memory_limit', -1);
echo ini_get('memory_limit');
exit;
can return 128M as output?
To change the memory limit for PHP-FPM, add the following line to your php-fpm.conf file:
php_admin_value[memory_limit] = -1
from fpm-config
; php_value/php_flag - you can set classic ini defines which can
; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
You must chose better solution for you. I'm prefer set lower memory limit in global config, and in places (wo I can't rewrite better) I'm add ini_set('memory_limit', xxx);
When I tail my /var/log/apache2/error_log file, it is truncating some data I am trying to display.
Example:
error_log(serialize($data));
As I understand it, the PHP INI Setting "log_errors_max_len" determines how long this is. And by default is is 1024. Mine is truncating at 8109 characters.
I have changed the value by using:
ini_set('log_errors_max_len', 0);
/etc/php5/apache2/php.ini (log_errors_max_len = 0)
/etc/php5/cli/php.ini (log_errors_max_len = 0)
Note: I am restarting Apache after each change to the php.ini file.
Unfortunately, none of these setting changes seem to change the amount of data that is displayed before truncating.
Anyone have a suggestion?
Thanks!
I have multiple system running on PHP 5.3 that are 15-10 years old, I can't go on those and change anything.
Problem is: some of those system are using PHP register_globals = on that is depreciate on PHP 5.3 and doesn't even exist in PHP 5.4 (http://php.net/manual/en/security.globals.php).
I am developing a new system and would like to turn PHP register_globals = off But I can't because all those old system that NEEDS it.
So I thought about dynamically changing the register_globals to off in my script using string ini_set ( string $varname , string $newvalue ) but the documentation (http://php.net/manual/en/function.ini-set.php) baffles me a bit:
Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.
Does that mean that if I have two script running at the same time lets say... One of my old system that really needs register_globals = on and my new system that use ini_set() to register_globals = off that the old script will be running with the newly changed setting? Or will it keep the setting in my PHP.ini file and the new system will run on the ini_set() configuration?
--EDIT--
After some test (see code below) #Jacob was right and it seems PHP create a context for each script and that ini_set() only change the configuration of the script its in.
TestWithIni_Set.php
<?php
ini_set('register_globals', '0');
$i = 0;
while(true)
{
if($i == 0)
{
phpinfo();
}
$i++;
}
?>
TestWithoutIni_Set.php
<?php
phpinfo();
?>
So I ran TestWithIni_Set.php first, then will TestWithIni_Set.php was executing (the infinite while loop) I ran TestWithoutIni_Set.php.
Unfortunatly, it seams like I can't change register_globals value with ini_set(). I tried the following:
//Knowing that ini_set() parameters are strings I tried those anyway.
ini_set('register_globals', '0');
ini_set('register_globals', 0);
ini_set('register_globals', 'off');
ini_set('register_globals', 'Off');
ini_set('register_globals', false);
ini_set('register_globals', 'false');
Then to make sure I didn't had something wrong in my code I tried:
ini_set('log_errors', '0');
Just to see if it would work and it did. Then value of log_errors for the script with ini_set() was off and the value of log_errors for the script without ini_set() was on.
But now I have a different problem.
How can I change the value of register_globals for only the running script if I can't change it using ini_set()?
I added a .user.ini file to my new system dir with the only line being register_globals=off.
I also went and uncomment the following line in my PHP.ini file:
user_ini.filename = ".user.ini"
I also made sure only a local user had the rights to make changes to that dir. So somebody couldn't go and upload a new user define .ini file for my server within this dir.
For exemple: IIS user can only read the file in this dir and can't add/modify/remove any file.
The Issue
When uploading files of around 8MB or over, I recieve a 500 Internal Server Error.
All PHP settings in php.ini are correct
maxAllowedContentLength has been set in the web.config
Server Info
As one can probably tell from the maxAllowedContentLength, I am running IIS 7.5, with FastCGI and PHP 5.3.17
Additional Info
I have tried so many different things to get this working but simply cannot find the issue.
However, I have found the following bits of info that may help figure out the root of this problem:
When uploading files (larger ones) using the Media Wiki that I have on the server, I receive the same error, this goes to show that it is not an error in my code.
Most importantly - I managed to upload an 18MB file in the Plesk File Manager, this obviously means that Plesk was able to get around this config issue. I have tried to copy all of the Plesk Control Panel settings over to this domain in IIS but this does not seem to work.
The error is being returned before the script is executed, as I have tried writing exit; at the top to try to get a blank screen, but this is ignored and the 500 error is returned.
I think that the issue lies within the configure command part of the PHP configuration, because when I change the handler mapping of the .php files to use the Plesk php-cgi.exe instead of the usual one, I do not get the 500 Internal Error. Having said that, I cannot leave it on this PHP version as it is Plesk's own exe and there are other configuration issues.
The reason why I think it may be to do with the configure command, is simply because this differs hugely from one phpinfo() to the other.
If you have any ideas or suggestions, please post them. I have tried everything to my knowledge and cannot seem to fix this. If only it was Linux...
Thanks in advance
UPDATE 1
Forgot to add, there are no errors being returned in the PHP error log. As for IIS errors, I do not know where to look
UPDATE 2
This is what I have placed in my web.config file:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
UPDATE 3
With your help, we have managed to get the error displayed by IIS. This is what I am receiving:
PHP Warning: POST Content-Length of 12221448 bytes exceeds the limit
of 8388608 bytes in Unknown on line 0
Is that to do with post_max_size?
UPDATE 4
PHP settings as follows (from phpinfo()):
post_max_size = 64M
memory_limit = 128M
max_file_uploads = 20
max_execution_time = 6000
upload_max_filesize = 64M
UPDATE 5
Lastly, just in case anybody can spot any potential issues, Plesk is able to upload large files absolutely fine, so I assumed that their php-cgi.exe was compiled differently. When I read a phpinfo() of their configuration the configure command information was very different:
My configuration:
cscript /nologo configure.js "--enable-snapshot-build"
"--disable-isapi" "--enable-debug-pack" "--without-mssql"
"--without-pdo-mssql" "--without-pi3web"
"--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared"
"--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared"
"--with-mcrypt=static" "--disable-static-analyze"
Plesk's Configuration:
cscript /nologo configure.js "--enable-debug-pack" "--enable-cli"
"--enable-cgi" "--enable-isapi" "--enable-one-shot" "--enable-pdo"
"--enable-intl" "--with-openssl=shared" "--with-pdo-odbc"
"--with-iconv" "--with-xml" "--with-xsl" "--with-mysql"
"--with-mysqlnd" "--with-mysqli" "--with-pdo-sqlite"
"--with-pdo-mysql" "--with-curl=shared" "--enable-mbstring"
"--enable-mbregex" "--with-imap=shared" "--enable-sockets"
"--enable-shmop" "--enable-soap"
UPDATE (ANSWER)
This is extremely weird as the phpinfo() info is saying one thing, but it is obviously being ignored, not sure why.
If I change the post_max_size in Plesk, for that particular domain/sub-domain, then nothing is changed (although it appears to have changed in the phpinfo()). However, if I actually change the post_max_value in the php.ini then this fixes the issue.
The reason why this is not a good way to fix this, is simply because when Plesk updates, the php.ini is overwritten as PHP is updated and resultantly the changes made to the php.ini are lost. Which means that everytime that Plesk updates I will need to make changes tot he php.ini. This is why Plesk offers the ability to change PHP settings without making changes to the php.ini.
Can anybody think of why PHP is ignoring the local value and reverting to the value in the php.ini, even though the php.ini states that the local value is different?
If you look at the source code of PHP, you can see on the file php-5.4.8-src\main\rfc1867.c line 706-709 this:
if (SG(post_max_size) > 0 && SG(request_info).content_length > SG(post_max_size)) {
sapi_module.sapi_error(E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size));
return;
}
Same is there also in file php-5.4.8-src\main\SAPI.c.
So, the message PHP Warning: POST Content-Length of 12221448 bytes exceeds the limit of 8388608 bytes in Unknown on line 0 is about post_max_size setting. You have confirmed from using phpinfo() that you have this setting configured correctly, but it seems to be using the default value of 8M anyway.
As to why, see this thread:
As it turns out, on Windows, you can only set ini directives that are
marked PHP_INI_USER per directory. Unfortunately,
upload_max_filesize and post_max_size are both PHP_INI_PERDIR.
From the PHP docs at
http://php.net/manual/en/configuration.changes.php
The settings for the directory would be active for any script running from this directory or any subdirectory of it. The values
under the key should have the name of the PHP configuration directive
and the string value. PHP constants in the values are not parsed.
However, only configuration values changeable in PHP_INI_USER can be set this way, PHP_INI_PERDIR values can not.
So even though Plesk has an interface to change those directives, and
even though phpinfo() picks up on them, they do nothing to change
the actual max upload sizes. Plesk should not allow you to change
those on Windows, and phpinfo() should not report the change, but
what can you do.
So, it's post_max_size, and it needs to be set on php.ini. Plesk setting simply will not work, even though phpinfo says otherwise. I also opened a bug entry on phpinfo behaviour as there didn't seem to be an entry for it.
This is a fairly common error and is due to the fact that the size of data being uploaded does not match file size: even if you POST max size is not exceeded by the file size, it could be by the uploaded data size.
See this page in the PHP manual.
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
Another source of troubles (for VERY large texts) is UTF8 encoding. You might find yourself with a "six megabytes" TEXTAREA that is actually 6 mega*characters*, and with international codepoints it might run to, say, 8.2 megabytes. Thus you get an apparently contradictory situation of "six megabytes data exceed the configured 8 megabytes limit".
Update
You report two apparently contradictory facts:
PHP settings as follows (from phpinfo()):
post_max_size = 64M
and
PHP Warning: POST Content-Length of 12221448 bytes exceeds the limit of 8388608 bytes
It is clear from the PHPINFO that the limit for POST is 64M. Yet the error says that the limit is 8M (the default). So it seems to me that your code is talking to two different PHP implementations (Two different virtual hosts? A CGI version and a non-CGI version in the same host? Two different machines?)
IIS will re-use the FastCGI processes. You will need to kill off any old processes to get php.ini to reload.
Edit the FastCGI module and edit 'monitor changes to file' and select the php.ini file. This will force the child processes to restart whenever you save an edit.
You could turn the limits to -1, that way, you won't ever have troubles about the size of the files.
It is probably no the best solution as you are basically saying "if I don't see it, it doesn't exist", but believe, it's really reliable and will always work.
I've tried everything to change the max_execution_time of a php crawler script so that it can run an infinite amount of time.
I have changed the php.ini file setting max_execution_time to 0 or 100000000 but with no change
I've also tried setting it from the php script itself by using ini_set('max_execution_time', 0);
All php scripts throw the same error Fatal error: Maximum execution time of 3000 seconds exceeded, what could I be missing and how can I make sure there is no max execution time limit?
php script
<?php
ini_set('MAX_EXECUTION_TIME', -1);
error_reporting(E_ALL); // turn on all errors, warnings and notices for easier debugging
//ini_set('max_execution_time', 123456);
ini_set('max_input_time', -1);
ini_set('memory_limit', '512M');
set_time_limit(0);
date_default_timezone_set('Europe/London');
/*code which scrapes websites*/
?>
phpinfo()
max_execution_time 0 0
max_input_time -1 -1
Try turning off safe mode in php and then try the below code
if( !ini_get('safe_mode') ){
set_time_limit(0); //this won't work if safe_mode is enabled.
}
This should allow you to run the script for infinite time.
In Apache you can change maximum execution time by .htaccess with this line
php_value max_execution_time 200
set_time_limit() php manual ref.
You shouldn't let your crawler run under apache, it's better to run it stand-alone via cli as part of a Gearman setup.
That way it won't hog your web server and it can run as long as you want. You can find many bindings for Gearman that you can use, including PHP of course.
use
set_time_limit(0);
at the top of the script
In WAMP there is three PHP.ini files so you might find 3 in xampp also, so just search for it with find and replace max_execution_time to what you are setting. But you must keep something small not too large as for speedy the app you running.
You could also try setting ignore_user_abort(TRUE); in your script as it might be the browser timing out rather than the script.
From the php.net manual
<?php
// Ignore user aborts and allow the script
// to run forever
ignore_user_abort(true);
set_time_limit(0);
See here for more info
http://www.php.net/manual/en/function.ignore-user-abort.php
If you are on windows, and this is a CLI run script maybe read this.
check phpinfo() from a temp script and search for max_execution_time. make sure that it has same value what you are setting. default should be 30 seconds. try to change it to a couple of different values and restart apache then check the value in phpinfo() to confirm.
if when you change the value it is reflected properly in the phpinfo() it means that there is some code in your script which is changing this value. search for two things in your code:
search your code for ini_set() and check if it is change max_execution_time
search for set_time_limit()
these functions can change maximum time limit of execution from script. otherwise you should check .htaccess from where this value may be set. but this will effect phpinfo() also.
I found the following in the xampp documentation. Maybe you are trying to edit the wrong php.ini file?
Why have changes in my php.ini no effect?
Since XAMPP 1.7.1 the "php.ini" is only in the directory "\xampp\php". Till XAMPP 1.7.0 is was in the directory "\xampp\apache\bin".
If a change in the "php.ini" have no effect, it's possible PHP is still using an other one. You can verify this with phpinfo(). Go to the URI localhost/xampp/phpinfo.php and search for "Loaded Configuration File". This value shows you the "php.ini" PHP is really using.
Info:
After changing the "php.ini" you have to restart Apache, thus Apache/PHP can read the new settings.
what you are doing is just setting the max_execution_time to whatever inside your page.
you can't change this using ini_set. you can change the memory_limit only.
see more details here...
from the php official site.
if you want them to be changed, change in php.ini.
You have to change both of these in you php.ini ( and check if that's the right php.ini by finding the location in phpinfo(); output! )
max_execution_time = 0
max_input_time = 0
And after that check if some php file is not overwriting those variables locally.
open php.ini notepad file and search or find upload_max_filesize = 1000M and you should change on Post_max_filesize = 1000M then restart your xampp and refresh the local phpmyadmin..