Why won't my server accept files larger then 2MB? - php

I have a VPS that runs XAMPP and gives service to an iPhone App that I made.
I used ASIHTTPRequest to upload files to the server.
The App sends files to the server, and the server accept only those who are lighter then 2MB.
I also checked with Wireshark and found this warning:
PHP Fatal error: Maximum execution time of 60 seconds exceeded in c:/xxx/index.php in line 2
in line 2 I wrote: session_start();
in my theory they are 2 things that block big files from entering my server:
Some kind of file size limit
Some kind of time limit per action
I really need help on this one. Thanks!

Check the settings in your php.ini file which, when running XAMPP, can be found in the *root*/php/ directory.
#Make sure file uploads are turned on
file_uploads = On
#Change the max upload size to 100Mb
upload_max_filesize = 100M
#Change the max post size to 100Mb
post_max_size = 100M
#Change the max upload time to 900seconds
max_input_time = 900
#This is where you are seeing your problem as the script execution is timing out.
#Change the max execution time of the script to 900 seconds
max_execution_time = 900

Check the following lines in your php.ini file:
upload_max_filesize = 2M
max_execution_time = 300
You might have to restart your server afterwards.

The error says: Maximum execution time of 60 seconds exceeded
This makes me think that your internet-connection is slow, thus the upload is taking more than the max_execution_time
To see what the max_execution_time currently is:
$maxtime = ini_get(max_execution_time);
echo $maxtime;
To make the max_execution_time bigger for the current page, enter this line on top of your PHP-file:
ini_set("max_execution_time", 600);?>

Put at the topo of your index.php:
<?php
ini_set('max_execution_time', 180); //Put the number of seconds that you want
The upload_max_filesize can't be change in runtime, so you need to increase this value in your php.ini

Related

Ajax request is getting cancelled

In a php application. I am uploading 20-30 files at once. Each files is around 100-200MB. Means more than 2GB of data i am uploading on server.
Because it takes time around 20-30 mins to upload. One general ajax pooling job getting cancelled after some time.
I have following configuration:
upload_max_filesize = 4096M
post_max_size = 4096M
max_input_time = 600
max_execution_time = 600
During this process my CPU consumption goes only upload 10-20%. I have 32 GB RAM and 12 CORE Linux machine.
Application is running on PHP 8.0, APACHE 2, MYSQL 8, Ubuntu 20.
Can anyone suggest what else i can check?
max_execution_time: This sets the maximum time in seconds a script is
allowed to run before it is terminated by the parser. This helps
prevent poorly written scripts from tying up the server. The default
setting is 30. When running PHP from the command line the default
setting is 0.
max_input_time: This sets the maximum time in seconds a script is
allowed to parse input data, like POST and GET. Timing begins at the
moment PHP is invoked at the server and ends when execution begins.
The default setting is -1, which means that max_execution_time is used
instead. Set to 0 to allow unlimited time.
I think change it:
max_input_time = 1800 & max_execution_time = 1800 (30 minutes)

Comment résoudre ce problème lié à l'installation de glpi sur wampserver? [duplicate]

How to increase transaction timeout? I want to upload videos, but large size of videos not uploaded?
It throws error The process *** exceeded the timeout of 60 seconds.
You need to change some settings in your php.ini:
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must - sets the maximum time in seconds
Where your PHP.ini is located depends on your system environment. For more information: http://php.net/manual/en/ini.list.php
You should be able to do during runtime too using
set_time_limit(100);
http://php.net/manual/en/function.set-time-limit.php
or in your vhost-config
php_admin_value max_execution_time 10000
Having a global execution time limit that is LOW is mostly a good idea for performance-reasons on not-so-reliable applications. So you might want to only allow those scripts to run longer that absolutely have to.
p.s.: Dont forget about post_max_size and upload_max_filesize (like the first answer told allready)
To complete the answer of Hannes.
You need to change some setting in your php.ini:
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must
If someone want put in unlimited (I don't know why but if you want), you can set the time to 0:
You need to change some setting in your php.ini:
upload_max_filesize = 0
max_execution_time = 0
And if you don't know where is your php.ini. You can do a file "name.php" in your server and put:
<?php phpinfo(); ?>
And on your website, you can see the config of your php.ini and it's marked where is it.
Edit on 9 January 2015:
If you can't access your php.ini, you have two more options.
You can set this line directly in your "name.php" file but I don't find for upload_max_filesize for this option:
set_time_limit(0);
Or in ".htaccess"
php_value upload_max_filesize 0
php_value max_execution_time 0
if what you need to do is specific only for 1 or 2 pages i suggest to use set_time_limit so it did not affect the whole application.
set_time_limit(some_values);
but ofcourse these 2 values (post_max_size & upload_max_filesize) are subject to investigate.
you either can set it via ini_set function
ini_set('post_max_size','20M');
ini_set('upload_max_filesize','2M');
or directly in php.ini file like response above by Hannes, or even set it iin .htaccess like below
php_value upload_max_filesize 2M
php_value post_max_size 20M
If you happen to be using Microsoft IIS server, in addition to the php.ini settings mentioned by others, you may need to increase the execution timeout settings for the PHP FastCGI application in the IIS Server Manager:
Step 1) Open the IIS Server Manager (usually under Server Manager in the Start Menu, then Tools / Internet Information Services (IIS) Manager).
Step 2) Click on the main connection (not specific to any particular domain).
Step 3) Under the IIS section, find FastCGI Settings (shown below).
Step 4) Therein, right-click the PHP application and select Edit....
Step 5) Check the timeouts (shown below).
In my case, the default timeouts here were 70 and 90 seconds; the former of which was causing a 500 Internal Server Error on PHP scripts that took longer than 70 seconds.
As an addition to above answers, you may use set_time_limit() function:
http://php.net/manual/en/function.set-time-limit.php
passing 0 as an argument will make your script run with no time limit.
If you cannot edit php.ini (on your server for example) you can attempt to change the php.ini parameters from within your php code. Try:
ini_set('max_execution_time', 'NUMBER OF SECONDS TO ALLOW BEFORE TIMEOUT');
If that doesn't work, try also setting 'set_time_limit' in the same way, beyond that I'd say your only option is to contact your host. These settings cannot be modified while in safe mode.
You had a typo: ini_set('max_input_time','200M') - value set needs to be an int, like ini_set('max_input_time','200')
I know you are specifically asking about the PHP timeout, but what no one else seems to have mentioned is that there can also be a timeout on the webserver and it can look very similar to the PHP timeout.
So if you have tried:
Increasing the timeout in php.ini by adding a line: max_execution_time = {number of seconds i.e. 60 for one minute}
Increasing the timeout in your script itself by adding: ini_set('max_execution_time','{number of seconds i.e. 60 for one minute}');
And you have checked with the phpinfo() function that max_execution_time has indeed be increased, then you might want to try adding this to .htaccess which will make sure Apache itself does not time out:
RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]
More info here:
https://www.antropy.co.uk/blog/php-script-keeps-timing-out-despite-ini-set/
First check the php.ini file path by phpinfo(); and then changed PHP.INI params:
upload_max_filesize = 1000M
memory_limit = 1500M
post_max_size = 1500M
max_execution_time = 30
restarted Apache
set_time_limit(0); // safe_mode is off
ini_set('max_execution_time', 500); //500 seconds
Note: you can also use command to find php.ini in Linux
locate `php.ini`
Test if you are is safe mode - if not - set the time limit (Local Value) to what you want:
if(!ini_get('safe_mode')){
echo "safe mode off";
set_time_limit(180);// seconds
phpinfo();// see 'max_execution_time'
}
*You cannot set time limit this way if safe mode 'on'.
optional : if you set config about php.ini but still can't upload
-this is php function to check error code
$error_type = [];
$error_type[0] = "There is no error";
$error_type[1] = "The uploaded file exceeds the upload_max_filesize directive in php.ini.";
$error_type[2] = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
$error_type[3] = "The uploaded file was only partially uploaded.";
$error_type[4] = "No file was uploaded.";
//$error_type["5"] = "";
$error_type[6] = "Missing a temporary folder. Introduced in PHP 5.0.3.";
$error_type[7] = "Failed to write file to disk. Introduced in PHP 5.1.0.";
$error_type[8] = "A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.";
//------------------------------
//--> show msg error.
$status_code = $_FILES["uploadfile"]["error"];
if($status_code != 0){
echo $error_type[$status_code];
exit;
}
You can also set a max execution time in your .htaccess file:
php_value max_execution_time 180
To really increase the time limit i prefer to first get the current value. set_time_limit is not always increasing the time limit. If the current value (e.g. from php.ini or formerly set) is higher than the value used in current call of set_time_limit, it will decrease the time limit!
So what's with a small helper like this?
/**
* #param int $seconds Time in seconds
* #return bool
*/
function increase_time_limit(int $seconds): bool
{
return set_time_limit(max(
ini_get('max_execution_time'), $seconds
));
}
// somewhere else in your code
increase_time_limit(180);
See also: Get max_execution_time in PHP script

openfit php fatal error database error [duplicate]

I am downloading a JSON file from an online source and and when it runs through the loop I am getting this error:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\temp\fetch.php on line 24
Your loop might be endless. If it is not, you could extend the maximum execution time like this:
ini_set('max_execution_time', '300'); //300 seconds = 5 minutes
and
set_time_limit(300);
can be used to temporarily extend the time limit.
I had the same problem and solved it by changing the value for the param max_execution_time in php.ini, like this:
max_execution_time = 360 ; Maximum execution time of each script, in seconds (I CHANGED THIS VALUE)
max_input_time = 120 ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB by default)
I hope this could help you.
All the answers above are correct, but I use a simple way to avoid it in some cases.
Just put this command in the begining of your script:
set_time_limit(0);
I ran into this problem while upgrading to WordPress 4.0. By default WordPress limits the maximum execution time to 30 seconds.
Add the following code to your .htaccess file on your root directory of your WordPress Installation to over-ride the default.
php_value max_execution_time 300 //where 300 = 300 seconds = 5 minutes
Edit php.ini
Find this line:
max_execution_time
Change its value to 300:
max_execution_time = 300
300 means 5 minutes of execution time for the http request.
Your script is timing out. Take a look at the set_time_limit() function to up the execution time. Or profile the script to make it run faster :)
if all the above didn't work for you then add an .htaccess file to the directory where your script is located and put this inside
<IfModule mod_php5.c>
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value memory_limit 300M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value session.gc_maxlifetime 1200
</IfModule>
this was the way I solved my problem , neither ini_set('max_execution_time', 86400); nor set_time_limit(86400) solved my problem , but the .htaccess method did.
We can solve this problem in 3 different ways.
1) Using php.ini file
2) Using .htaccess file
3) Using Wp-config.php file ( for Wordpress )
You can remove the restriction by seting it to zero by adding this line at the top of your script:
<?php ini_set('max_execution_time', '0'); ?>
Follow the path /etc/php5(your php version)/apache2/php.ini.
Open it and set the value of max_execution_time to a desired one.
To extend your max_execution_time you can use either ini_set or set_time_limit.
// Set maximum execution time to 10 seconds this way
ini_set('max_execution_time', 10);
// or this way
set_time_limit(10);
!! But be aware that, both functions restarts also counting of time script has already taken to execute
sleep(2);
ini_set('max_execution_time', 5);
register_shutdown_function(function(){
var_dump(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
});
for(;;);
//
// var_dump outputs float(7.1981489658356)
//
so if you want to set exact maximum amount of time script can run, your command must be very first.
Differences between those two functions are
set_time_limit does not return info whether it was successful but it will throw a warning on error.
ini_set returns old value on success, or false on failure without any warning/error
Maybe check for any thing that you have changed under the php.ini file.
For example I changed the ";intl.default_locale =" to ";intl.default_locale = en_utf8" in order to enable the "Internationalization extension (Intl)" without adding the "extension=php_intl.dll" then this same error occurred. So I suggest to check for similar mistakes.
Increase your script execution time by adding the following line at top of the PHP script.
ini_set('max_execution_time', 120); //120 seconds = 2 minutes
Reference has taken from Increase the PHP Script Execution Time
You can do it easily with WHM. Just got to:
WHM -> Service Configuration -> PHP configuration
editor-> max_execution_time=30
( 30 is default change it to whatever value u want)
set_time_limit($time_in_second); // 0 for unlimited time
I use this php function in run time if need to run a script for long.
Details here.
I have same problem in WordPress site,
I added in .htaccess file then working fine for me.
php_value max_execution_time 6000000
I have make some changes in my case in: xampp\phpMyAdmin\libraries\config.default.php
i have searched for : $cfg['ExecTimeLimit'] and change the value at right side...
You can change Right hand Value to any higher value, like '5000'. and it works.

Fatal error : execution time of 30 seconds exceeded in phpMyAdmin

I have a MySQL table which contains 6.5 million records. When I try to access that table from phpMyAdmin I get:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp-new\phpMyAdmin\libraries\display_tbl.lib.php on line 1457.
I am just trying to view the records and I am not doing any query which might cause the error.
This problem is only in my server. And my local machine does not contain as many records as the server.
In my php.ini I have already set the maximum execution time to maximum.
How do I fix this error?
Add this line
$cfg['ExecTimeLimit'] = 6000;
to phpmyadmin/config.inc.php
And Change php.ini and my.ini
post_max_size = 750M
upload_max_filesize = 750M
max_execution_time = 5000
max_input_time = 5000
memory_limit = 1000M
max_allowed_packet = 200M (in my.ini)
if you are using xammp on the xammp control panel at the apache line click on config and then click to open PHP(php.ini) find and increase max_execution_time=30 to max_execution_time=600.
+1 for making me lookup lakhs. That looks like a PHP timeout to me as the default timeout is 30 seconds. Increase the setting in your php.ini and restart apache and see if the timeout persists.
http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time
you need to set max_execution_time in php.ini
max_execution_time=6000
HAPPY CODING
This solution has resolved the issue
Place the following lines at the top of the script page and before the query that initiates the memory:
ini_set('max_execution_time', 0);
set_time_limit(1800);
ini_set('memory_limit', '-1');
Go to:
xampp\phpMyAdmin\libraries\config.default.php
Look for : $cfg['ExecTimeLimit'] = 600;
change '600' to '6000'.
Open the xampp folder at your computer where it is installed. For example, it is at C: drive into my PC, and then open the phpMyAdmin and then libraries folder.
"C:\xampp\phpMyAdmin\libraries”
you will find a file there named, "config.default.php". Open the file into any editor or in notepad and find the line "$cfg['ExecTimeLimit'] = 300;", change the value to 0. i.e. $cfg['ExecTimeLimit'] = 0; and save the file. After saving the file restart your xampp control panel.
Hurrah! Your problem has been solved.

Apache retrieve a timeout error and closes connection when uploading large files

I've been trying to reconfigure my apache and php.ini to allow upload of large file.
therefore I've changed the following variables:
/httpd/conf/httpd.conf:
Timeout 7200
ProxyTimeout 7200
/etc/php.ini:
post_max_size = 1024M ; Maximum size of POST data that PHP will accept.
max_execution_time = 7200 ; Maximum execution time of each script, in seconds
max_input_time = 7200 ; Maximum amount of time each script may spend parsing request data
memory_limit =1024M ; Maximum amount of memory a script may consume
file_uploads = On ; Whether to allow HTTP file uploads.
upload_max_filesize = 1024M ; Maximum allowed size for uploaded files.
PHP script - before uploading:
set_time_limit(0);
The response is :
324(net::ERR_EMPTY_RESPONSE)
Please notice that the uploaded file is stored correctly at the server, so the upload process is successful, but I keep getting this error.
Any hint?
Alon kogan
My answer is very late but maybe I'll help someone.
I decided the problem when I lower memory_limit
P.S. Sorry for my English

Categories