phpMyAdmin timeout not respecting PHP.ini max_execution_time - php

Trying to import a 150MB .sql.zip file into WAMP phpMyAdmin using this method (saving the import file in c:/wamp/sql, and editing C:\wamp\apps\phpmyadmin5.0.2\config.inc.php to include $cfg['UploadDir'] = 'C:\wamp\sql'; at the end, then an option to import the file save to C:\wamp\sql during the import process.
However, I keep receiving a timeout error in phpMyAdmin, with advice to rerun the import selecting the same file, but on the 2nd run I always receive SQL errors.
So, I've set max_execution_time = 4500 in Wamp's PHP.ini (4500 seconds equals 75 minutes) and restarted Apache and MySQL.
However, the same timeout error occurs when using the same import process. The timeout error occurs after about 5 minutes.
Why is the timeout error occurring within 5 minutes and not within the time set by PHP.ini max_execution_time = 4500 ?
Edit
phpinfo says localhost has:
memory_limit 200M
post_max_size 200M
upload_max_filesize 200M
max_execution_time 4500
I continue to receive the message that a timeout has occurred and to rerun the import again with the same file, but on the 2nd run, I receive an error:
Error
Static analysis:
2 errors were found during analysis.
Unexpected beginning of statement. (near "RT" at position 0)
Unrecognized statement type. (near "INTO" at position 3)
SQL query: Copy
RT INTO `cache_menu`
It looks like the SQL INSERT command is being cut by the process.
How can I safely split the SQL into smaller chunks?

Apart from maximum execution time, PHP will also have limits on post maximum size, memory limit, upload max filesize. (all of them can be related to the upload file operation for data import). If any one of them reaches the allowed limit, will cause failure of the execution and throw a time-out error
Hence you may set /change the following
ini_set('memory_limit', '40M');
ini_set('max_execution_time', 80000);
ini_set('post_max_size', '40M');
ini_set('upload_max_filesize', '40M');

I am unsure if this is an adequate solution for someone encountering the same problem but my workaround was to split the large SQL file into smaller files using SQL Dump File Splitter

Related

Importing large excel file using laravel application

I managed to build a project similar to the video: "Import CSV in Laravel 5.5 + Matching Fields"
Using excel import instead of CSV, it works fine with small excel files (less than 1000 rows) but I have excel files with more than 13000 rows the app keeps issuing the following error:
Maximum execution time of 30 seconds exceeded
Level
ERROR
Exception
{
"class": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
"message": "Maximum execution time of 30 seconds exceeded",
"code": 1,
.
.
.
I tried different ways and I read Laravel Excel documentation > Import Section > Chunk Reading and Queued reading but this also didn't work as I import excel file to collection then match the fields and then create new models and save them.
Please, advice for any tip can help me to import large excel files and match database fields with excel file column headings.
Change You PHP Configuration. Increase time by below 4 Ways.
Increase the execution time at php.ini level,
max_execution_time=300
Use PHP at runtime to increase it,
ini_set('max_execution_time',300); //300 seconds = 5 minutes
Use inside the .htaccess to increase it,
php_value max_execution_time 300
set time limit in __construct method or you can set in your index controller also where you want to have large time limit.
public function __construct()
{
set_time_limit(500000);
}
Some times I receive 504 Gateway Time-out and sometimes I get laravel error:
Maximum execution time of 30 seconds exceeded or the value I set in max_execution_time as suggested by #Vaibhavi Sojitra
With these errors, it may be any of the following PHP parameters in the php.ini that is causing the PHP process to end abruptly, thus causing Nginx to get a "reset" from its peer (in this case, the php-fpm backend).
I couldn't come to a better laravel technique to solve this issue, the solution that worked for me (till I find a better one):
increase the following parameters in php.ini
max_input_time = ...
max_execution_time = ...
default_socket_timeout = ...
After that the import process worked well.

How to prevent timeout when running a time consuming PHP

I am using PHP that gets so many data from several sites and write those data to the server which make files greater than 500 MB, but the process fails in between giving a 500 INTERNAL ERROR, how to adjust the timeout time of the php so that the process runs till it is completed.
If you want to increase the maximum execution time for your scripts, then just change the value of the following setting in your php.ini file-
max_execution_time = 60
If you want more memory for your scripts, then change this-
memory_limit = 128M
One more thing, if you keep on processing the input(GET or POST), then you need to increase this as well-
max_input_time = 60
you have to set some settings in the php.ini to solve this problem.
There are some options which could be the problem.
Could you pls post your php.ini config?
Which kind of webserver do you use?Apache?

PHP: maximum execution time when importing .SQL data file

I am trying to import a large .sql data file using phpMyAdmin in XAMPP. However this is taking a lot of time and I keep getting:
Fatal error: Maximum execution time of 300 seconds exceeded in C:\xampp\phpMyAdmin\libraries\dbi\DBIMysqli.class.php on line 285
And the file is about 1.2 million lines long.
The file is about 30MB big, so it is not that big. I don't really understand why it is taking so long.
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time=30000
; Maximum amount of time each script may spend parsing request data. It's a good
; idea to limit this time on productions servers in order to eliminate unexpectedly
; long running scripts.
; Note: This directive is hardcoded to -1 for the CLI SAPI
; Default Value: -1 (Unlimited)
; Development Value: 60 (60 seconds)
; Production Value: 60 (60 seconds)
; http://php.net/max-input-time
max_input_time=60
; Maximum input variable nesting level
; http://php.net/max-input-nesting-level
;max_input_nesting_level = 64
; How many GET/POST/COOKIE input variables may be accepted
; max_input_vars = 1000
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit=200M
The is the config file for php.ini in xampp, for some reason i still get
Fatal error: Maximum execution time of 300 seconds exceeded in C:\xampp\phpMyAdmin\libraries\dbi\DBIMysqli.class.php on line 285.
There's a configuration variable within the phpMyAdmin directory that you can find in phpmyadmin\config.inc.php called $cfg['ExecTimeLimit'] that you can set to whatever maximum execution time you need.
Well, to get rid of this you need to set phpMyadmin variable to either 0 that is unlimited or whichever value in seconds you find suitable for your needs. Or you could always use CLI(command line interface) to not even get such errors(For which you would like to take a look at this link.
Now about the error here, first on the safe side make sure you have set PHP parameters properly so that you can upload large files and can use maximum execution time from that end. If not, go ahead and set below three parameters from php.ini file,
max_execution_time=3000000 (Set this as per your req)
post_max_size=4096M
upload_max_filesize=4096M
Once that's done get back to finding phpMyadmin config file named something like "config.default.php". On XAMPP you will find it under "C:\xampp\phpMyAdmin\libraries" folder. Open the file called config.default.php and set :
$cfg['ExecTimeLimit'] = 0;
Once set, restart your MySQL and Apache and go import your database.
Enjoy... :)
Set Only 3 Parameters from php.ini file of your server
A. max_execution_time = 3000000 (Set as per your requirment)
B. post_max_size = 4096M
C. upload_max_filesize = 4096M
Edit C:\xampp\phpMyAdmin\libraries\config.default.php Page
$cfg['ExecTimeLimit'] = 0;
After all set, restart your server and import again your database.
Done
You're trying to import a huge dataset via a web interface.
By default PHP scripts run in the context of a web server have a maximum execution time limit because you don't want a single errant PHP script tying up the entire server and causing a denial of service.
For that reason your import is failing. PHPMyAdmin is a web application and is hitting the limit imposed by PHP.
You could try raising the limit but that limit exists for a good reason so that's not advisable. Running a script that is going to take a very long time to execute in a web server is a very bad idea.
PHPMyAdmin isn't really intended for heavy duty jobs like this, it's meant for day to day housekeeping tasks and troubleshooting.
Your best option is to use the proper tools for the job, such as the mysql commandline tools. Assuming your file is an SQL dump then you can try running the following from the commandline:
mysql -u(your user name here) -p(your password here) -h(your sql server name here) (db name here) < /path/to/your/sql/dump.sql
Or if you aren't comfortable with commandline tools then something like SQLYog (for Windows), Sequel Pro (for Mac), etc may be more suitable for running an import job
This worked for me.
If you got Maximum execution time 300 exceeded in DBIMysqli.class.php file. Open the following file in text editor
C:\xampp\phpMyAdmin\libraries\config.default.php then
search the following line of code:
$cfg[‘ExecTimeLimit’] = 300;
and change value 300 to 900.
https://surya2in1.wordpress.com/2015/07/28/fatal-error-maximum-execution-time-of-300-seconds-exceeded/
Simply set $cfg['ExecTimeLimit'] = 0; In xampp/phpMyAdmin/libraries/config.default.php.
Maximum execution time in seconds (0 for no limit).
And make this below changes in php.ini file as per file size.
post_max_size = 600M
upload_max_filesize = 500M
max_execution_time = 5000
max_input_time = 5000
memory_limit = 600M
But make sure 'post_max_size' and 'memory_limit' should be more than upload_max_filesize.
**Note - Don't forget to restart your server.
If you are using the laragon and your database is phpMyAdmin the process is the same for tackle this error.
Open laragon right-click on it and open php.ini file
set these value accordingly to your needs
max_execution_time
post_max_size
upload_max_filesize
Open new file config.default.php
path is C:\laragon\etc\apps\phpMyAdmin\libraries\config.default.php
and set the value of this $cfg['ExecTimeLimit'] = 0;
Restart the laragon.
I hope it would solve your problem for laragon environment 🙏 #Happy Coding :)
Is it a .sql file or is it compressed (.zip, .gz, etc)? Compressed formats sometimes require more PHP resources so you could try uncompressing it before uploading.
However, there are other methods you can try also. If you have command-line access, just upload the file and import with the command line client mysql (once at the mysql> prompt, use databasename; then source file.sql).
Otherwise you can use the phpMyAdmin "UploadDir" feature to put the file on the server and have it appear within phpMyAdmin without having to also upload it from your local machine.
This link has information on using UploadDir and this one has some more tips and methods.
you must change php_admin_value max_execution_time in your Alias config (\XAMPP\alias\phpmyadmin.conf)
answer is here:
WAMPServer phpMyadmin Maximum execution time of 360 seconds exceeded
After trying many things with no success, I've managed to get SSH access to the server, and import my 80Mb database with a command line, instead of phpMyAdmin. Here is the command:
mysql -u root -p -D mydatabase -o < mydatabase.sql
It's much easier to import big databases, if you are running xammp on windows, the path for mysql.exe is C:\xampp\mysql\bin\mysql.exe
1-make a search in your local drive and type "php.ini"
2-you may see many files named php.ini you should choose the one that fits with your php version (see localhost)
3-open the php.ini file make a search on "max_execution_time" then make it equal to "-1" to make it unlimited
Never change original config.default.php file.
Changing general executing time in php.ini has no effect on phpmyadmin scripts.
Use a new config.inc.php or the config.sample.inc.php provided in the /phpMyAdmin folder instead.
You can set $cfg[‘ExecTimeLimit’] = 0; means endless execution in the config.inc.php as recommended above. Be aware this is not a "normal" ini file. Its a php script, so you need a open <?php at the beginning of that file.
But most important: Do not use this procedure at all! phpmyadmin is okay for small database but not for huge databases with several MB or GB.
You have other tools on a server to handle the import.
a) If you have a server admin
system like Plesk, use there database import tool.
b) use ssh commands to make database dump or to write databases directly in
mysql via ssh. Commands below.
Create a database dump:
mysqldump DBname --add-drop-table -h DBhostname -u DBusername -pPASSWORD > databasefile.sql
Write a database to mysql:
mysql -h rdbms -u DBusername -pPASSWORD DBname < databasefile.sql
Best solution for this error when i tried some points.
Follow this steps to solve this issue:
locate the file [XAMPP Installation Directory]\php\php.ini (e.g. C:\xampp\php\php.ini)
open php.ini in Notepad or any Text editor
locate the line containing max_execution_time and
increase the value from 30 to some larger number (e.g. set: max_execution_time = 90)
then restart Apache web server from the XAMPP control panel
Changing the max_execution_timeout in php.ini. may help with maximum execution error. but sometimes the database is imported correctly but still it shows maximum execution time error, it can be due to some error of xamp.
I was experiencing the same error even after making all changes in php.ini. which is mentioned above and realized that all the things, tables of database were imported and it was working fine but it was still showing the max_execution_timeout error.
Set Only 3 Parameters from php.ini file of your server
A. max_execution_time = 3000000 (Set as per your requirment)
B. post_max_size = 4096M
C. upload_max_filesize = 4096M
Case 1 : If you are Using Xampp, Edit
C:\xampp\phpMyAdmin\libraries\config.default.php
Case 2 : If you are Using Wampp, Edit
c:\wamp64\apps\phpMyAdmin\libraries\config.default.php
Case 3 : If you are Using Laragon, Edit
C:\laragon\etc\apps\phpMyAdmin\libraries\config.default.php
search for $cfg['ExecTimeLimit'] in config.default.php file and make the following changes
$cfg['ExecTimeLimit'] = 0;
After all set, restart your server and import again your database.
Done
You can increase the limit:
ini_set('max_execution_time', 3000);
(Note that this script can cause high memory usage as well, so you probably have to increase that as well)
Other possible solution: Chunk your sql file, and process it as parts. I assume, it is not one big SQL query, is it?
Update: As #Isaac pointed out, this is about PHPMyAdmin. In this case set max_execution_timeout in php.ini. (The location depends on your environment)
The following might help you:
ini_set('max_execution_time', 100000);
And in your mysql - max_allowed_packet=100M in some cases where queries are too long sql also produce and error "MySQL server has gone away";
Change the values to whatever you need.

Reading a File with PHP gives 500 error

I have a script which reads a mp3 file with readfile() (I have also tried fread() with a loop). And on one particular file I am getting a 500 error. All other files seem to read just fine.
When I review the error log on my server I notice I am getting a PHP memory error when ever this particular file is attempted to be read.
Can anyone give me some pointers as to what might be going on?
You already pointed out the problem - PHP is running out of memory. Maximum memory usage in PHP is limited by an ini setting.
You can set it at runtime at the top of your script with ini_set:
ini_set('memory_limit', '64M');
Or you can set it in your php.ini file so it takes effect for all scripts:
memory_limit = 64M;
Finally, you can see the memory used by the currently executing script with memory_get_usage()
The mp3 file is of a larger filesize than memory_limit. You'll need to increase the amount of memory PHP can access if you want to read from this mp3 file.
If you have access to the php.ini file, you can find memory_limit = 16M ; and replace the value with however much memory you need.
If you don't have php.ini access and you do have .htaccess access, add:
php_value memory_limit 16M
and replace the value.
If you have neither, try compressing the mp3 file or otherwise reducing the amount of memory it will take for you to perform this action. Try clearing variables which are unused and take up large amounts of memory.
Well, php is probably running out of memory before completing the script. You can just increase the memory php is allowed to run by changing the memory_limit option in your php.ini.
Try increasing the execution time:
set_time_limit(300); //300 seconds
ini_set('memory_limit','16M'); //increase to some value like 16 MB
Most likely it exceeds maximum memory. This can be adjusted in the php.ini, check here: http://www.php.net/manual/en/ini.core.php#ini.memory-limit

PhpMyAdmin timeout with large SQL import error

When I try to paste a large(5000 lines) sql file into PhpMyAdmin, I get this error? I know I can use the upload but on my old version of PhpMyAdmin this used to work without a problem.
ALERT - configured request variable value length limit exceeded - dropped variable
'sql_query' (attacker '111.171.123.123', file '/usr/share/apache2/phpmyadmin/import.php'),
referer: https://example.co.uk/phpmyadmin/db_sql.php?db=test&server=1&
token=0f355f8bbc6fc09d5c512e0409e9cac9&db_query_force=1
I have already tried changing the $cfg['ExecTimeLimit'] = 0;
php.ini
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
; Maximum execution time of each script, in seconds
max_execution_time = 120
; Maximum amount of time each script may spend parsing request data
max_input_time = 60
;max_input_nesting_level = 64 ; Maximum input variable nesting level
;Maximum amount of memory a script may consume (128MB)
memory_limit = 100M
As far as I'm concerned this message means that Suhosin (a security patch for PHP) is blocking your request because of its length. The simplest way to solve your problem without changing Suhosin's config - is to import a file with the same SQL statements to PHPMyAdmin (it allows uploading files for import).
So basically all you need - is to create a simple text file, paste the same SQL statements into it, and upload this file to PHPMyAdmin - it has the appropriate page for such imports.
If you really want to use PhpMyAdmin try using the version 3.4.3.2 or higher as I am not sure if yours version has got this
Partial import
Allow the interruption of an import in case the script detects it is close to the PHP timeout limit. (This might be good way to import large files, however it can break transactions.)
http://www.phpmyadmin.net/home_page/index.php
I hope it helps.

Categories