Session Regenerate ID Exceeding Maximum Execution Time? - php

For some reason, on occasion, I get the following fatal error from my PHP code when running on a shared server:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\HostingSpaces[username][subdomain]\wwwroot\index.php on line 8
And that line is just:
session_regenerate_id();
Might this problem be from the code being hosted on a shared server and resources not being available? Or is there some other cause for this problem?
Since it's a shared server, I can't change any PHP settings.
EDIT:
The only line before line 8 are a few require_once lines for model objects. The only other line is session_start().
I checked my PHP settings and it states that the session.save_handler is files for both the local and master values. Since it is using files, might the problem be trying to read and write from the disk?

I think your problem might be a performance and resource issue as you suspect, but I find it strange that it has only stopped on line 8. I'd guess that the chances could be high if the rest of the code was very minimal.
Have you tried altering the code in an attempt to get the timeout to occur on a different line? For instance, you could try adding sleep(25); and see if the fatal timeout occurs on that line instead.
Also, are you certain that you cannot set the maximum execution time limit? I would suspect that even if you cannot alter the shared php.ini, you could set the max_execution_time through one of these other options:
Setting a php_value max_execution_time directive in an .htaccess
file
Using set_time_limit in your code
Using ini_set and max_execution_time in your code
I believe the value/argument for max_execution_time is in seconds, and if you set it to 0 (zero) then NO execution time limit will be used. (Whether you consider it safe to use zero or not is up to you.)

Related

Warning: simplexml_load_string(): Memory allocation failed

Facing an issue in excel sheet & CSV reader with large quantities of records in Codeignitor.
A PHP Error was encountered
Severity: Warning
Message: simplexml_load_string(): Memory allocation failed : growing buffer
Filename: Reader/Excel2007.php
Line Number: 645
Backtrace:
File: \application\third_party\PHPExcel\Reader\Excel2007.php
Line: 645
Function: simplexml_load_string
File: \application\controllers\admin\Csv.php
Line: 56
Function: load
File: \index.php
Line: 322
Function: require_once
The first option is to increase memory for php with the setting in the file php.ini.
memory_limit = 256M
The number can be lower and different but should be at least higher then it's now, but surely it can be higher than 256M too.
After the change perhaps the sever has to be restarted (depends on some things).
If that doesn't help, then it's worth it to look at the application and even the CSV-file.
Basic problem concerning most frameworks is that data are collected, hold in memory, parsed and then the results are shown or written in the database if applying.
Programs for big data have somehow to chunk the data and that also can mean just to streamline and processing step by step (like a video or soundfile).
As XMLis no stream-format but requires a fully parsed structure before it's processed usually the hint might look a bit useless. But perhaps there are a few things you could do to reduce the data-amount to be processed at once:
If simplexml is used to process several files at once it should be easy just to reduce the amount of files.
if the XML-file(s) are just too large you've to produce smaller files. It's also possible to split files but a little bit knowledge about XML is required for it.
In general it's possible that small tweaks at the implementation in CodeIgniter could solve the problem already, but as that one is unknown here we can only guess about it.
To increase PHP memory limit setting, edit your PHP.ini file. Simply increase the default value (example: Maximum amount of memory a script may consume = 128MB) of the PHP memory limit line in php.ini.
memory_limit = 256M
Alternatively you can edit your .htaccess file.
php_value memory_limit 256M
Note: If you don’t have access to these files or lack the experience to make this change, you can contact your web host and ask them to increase your PHP memory limit.

nginx +PHP 5.6.30 / FPM/FastCGI using set_time_limit(x) in a script causing fatal error

Whenever there is set_time_limit(x) in PHP script, it causes PHP fatal error after 30s of max execution time.
Any idea what might be wrong? I am not using set_time_limit() function, but many WordPress plugins and WordPress upgrade core PHP files do, causing me a headache.
<?php
set_time_limit(300);
echo 'test';
?>
Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/html/test.php on line 2
Thanks.
The cause of the problem is slowness. Increase the parameter to something bigger temporarily, or comment out those lines altogether. When you have finished with this, optimize your project, so a request will not take so long and when you are comfortable with the performance, you can put back the time limits. Also, it might be worth to ask the authors of the plugins whether they will release a version where you can enable/disable this feature or set the time limit yourself.

Maximum execution time fatal error when importing WordPress xml file

I want to upload xml file using WordPress Importer plugin. But I am getting this error "Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\us\wp-includes\class-http.php on line 1127" http://prntscr.com/7xbypv .
I was changed max_execution_time in php.ini file. But still getting same error.
The max execution time can be set in different places in the following order of precedence: php.ini, .htaccess, and in your PHP file. If you changed your max_execution_time to a value greater than 60 seconds and then restarted Apache (it appears you are using WAMP), you should see the new value you set in the error. If you are still seeing 60 seconds, it is possible that you set the value in the incorrect php.ini file (you can use php_info() to see which php.ini you are actually using) or that it is being overridden by either .htaccess or a value in the code you are using.
If this is a one time issue (local development or the like) you can add the following line to your wp-config.php to set the max execution time to 120 seconds (or other value). Setting this to 0 will disable the timeout entirely (should not be using in production).
set_time_limit(120);

Laravel Memory: 'out of memory (allocated 262144)'

I'm a system administrator which handles a server that hosts an internal api created using Laravel 5. The data source is a SQL Server hosted on another server and the api is used in a IOS app for mobile phones. When the developers created the api, this error was not present and no other memory errors were found. When we went live this error has been popping up from time to time.
[2015-06-01 23:01:52] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Out of memory (allocated 262144) (tried to allocate 140189808036120 bytes)' in Unknown:0
I checked RAM, CPU, swap etc etc of the server but everything was ok. Not much of the resources are being consumed. I've checked PHP Memory limit from php.ini and is set to -1 which is the max according to PHP. I've checked it on CLI, phpinfo.php and httpd.conf I don't see anything wrong. The team tried following this link Allowed memory size of X bytes exhausted
This is a problem in the ios app because the app searches for a correct return code but when this error comes out, even if the ios app transaction is correct, it returns an error because the return code is incorrect as it is returning the code for the memory error.
The first thing I could think of was to restart the Apache httpd service. This immediately solved the issue. but I knew this is not a permanent fix for the issue. When I researched further, I got to know that the error comes when certain PHP scripts require more memory than PHP was allowed by default.
So the solution is to increase the memory allocated for PHP. How to do that? There are 4 possible ways –
Try looking for the php.ini file. You might find some redundant php.ini files, so make sure you have got the one which is actually being read by PHP. o be sure, create a new php file in your root folder, say “check.php” and have phpInfo(); within the php open and close tags. Execute this file to get the information on where the php.ini is residing. Normally it will be in /usr/local/lib/php.ini
Open the php.ini file in a text editor like TextPad (not in Notepad) and change the values for memory_limit. By default you should see memory_limit = 8M. Try changing it to 12M. If it doesn’t work, increase it to 16M or even 24M and so on.
In case you can’t find the php.ini file or do not have access to it, then open up the file which was throwing the error (admin.php in my case) and add a line below just after ini_set(’memory_limit’, ‘12M’);
You can even consider adding a line in .htaccess file which will resolve the issue.
php_value memory_limit 32M
Or else, Try adding this line to your php file:
Increasing memory allocated to PHP
ini_set(“memory_limit”,”16M“);

Receiving "Input Variables Exceeded 1000" error even after updating max_input_vars

I'm running Magento, and I am receiving "mod_fcgid: stderr: PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0" when trying to save Related Products with 5000+ products in the DB.
Most people recommend trying to fix this by updating the max_input_vars to something higher. I went ahead and added max_input_vars = 100000 to php.ini, and added php_value max_input_vars 100000 to .htaccess for good measure.
php.ini is being updated, when I run php -i | grep max_input_vars it outputs max_input_vars => 100000 => 100000
I also tried smaller numbers like 5000, 6000 (in case for some reason 100000 is too high)
I did remember to restart apache2, so that is not the issue.
No matter what I do, I still receive "mod_fcgid: stderr: PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0"
Any ideas?
create a pi.php file with just the code:
<?php phpinfo();
in it and save it in the same folder as your Magento, then access via browser.
The value that will be displayed for max_input_vars (local column) is your run-time value. If it differs from your setting in php.ini, you're probably changing the wrong INI file.
Mod_FCGID can use a differenct file from the "classic" /etc/php.ini, or settings in any of the files in /etc/php.d/ - for instance - may override the ones in the "global file".
phpinfo() shows the list of parsed INI files, so you can see which to amend.
PLEASE remember to take off the file once you have fixed the issue: it's a likely security threat, as you show a lot of details that may be useful to hackers.
The problem arises from your Ajax XMLHttpRequest() function.
You are trying to send FormData information through XHttp.send(FormData) using wrong header.
In your ajax function erase any line of .setRequestHeader. E.g
XHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
erase that. It will be set to the proper headers by default.

Categories