error: out of memory / the connection was reset - php

I am trying to do a massive select * { insert into..} on a php page using xampp (v 5.5.30) on windows (64bit, 4 Gb ram).
After a few minutes I however get either two error messages:
A) "the connection was reset" in the browsers, or sometimes:
B) "mysql_query(): (HY000/2008): Out of memory..." during the insertion query.
On both occasions the PHP script itself is halted even using the directive:
ignore_user_abort(true);
I can't figure out why this is happening. Things I tried so for:
1) added in my apache config file:
<IfModule mpm_winnt_module> ThreadStackSize 8388608 </IfModule> because in the error log I noticed the line at the time of the connection reset:
[Mon Dec 07 13:01:23.540742 2015] [mpm_winnt:notice] [pid 2344:tid
504] AH00428: Parent: child process 4036 exited with status 3221225477
-- Restarting.
[Mon Dec 07 12:09:39.584814 2015] [mpm_winnt:notice] [pid 1684:tid
528] AH00354: Child: Starting 150 worker threads.
It seems like this error is linked to my problem in some way. Changing the config file however did not help and the error still appears.
2) Changed php ini setting:
ini_set("memory_limit","750MB");
3) Removed all mysql cache using:
RESET QUERY CACHE
4) Set PHP timeout:
set_time_limit(60*60);
The error occurs after a few minutes already.
Additional note: the filesize of the table used in the main select-query (mytable.MYD) is 400Mb, of which I only use a few columns of in the select. Once the query is loaded in the PHP memory, before executing the while loop, the memory footprint is 60Mb (using memory_get_usage())
Any idea what I can do to solve this?
thanks

You have to set execution time also.
set execution time to 0,it is functionally equivalent to turning the execution limit off completely:
ini_set('max_execution_time', 0);
Hope it will solve your problem

Related

How to solve issue with FastCGI: "Error reading data from FastCGI server"

My application contains some heavy processes (heavy db queries like
insert/update/delete queries by doctrine) and in some cases I get the following errors on the MySQL NGINX + PHP 7.4:
[Fri Apr 15 03:14:11.199479 2022] [fcgid:warn] [pid 2237536:tid 139805102909184] (104)Connection reset by peer: [clientx:50558] mod_fcgid: error reading data from FastCGI server
[Fri Apr 15 03:14:11.199523 2022] [core:error] [pid 2237536:tid 139805102909184] [client x:50558] End of script output before headers: index.php
The issue disappeared for a few days when I adjusted following variables:
FcgidBusyTimeout 1800
FcgidIOTimeout 1800
I adjusted also configuration for PHP (memory limit and max_execution_time).
I can see that problem occurs again (I think the process has more queries to perform). What else should I change for the FastCGI config to fix this issue?
Thank you in advance.

apache stop responding then crashes

Apache (2.4.25 FPM/FastCGI) stop responding and crashes after a while on my wordpress multisite website.
For some reason it used to run fine several days until I changed the wordpress(mu) domain using this script github.com/interconnectit/Search-Replace-DB (probably not the reason).
When restarted it works for about an hour then choked again.
I have added a mysql slow query log but its empty.
Apache error_log has multiple errors like this one:
[Wed Sep 06 08:50:27.941819 2017] [proxy_fcgi:error] [pid 25444:tid 140610719610624] (70007)The timeout specified has expired: [client x.x.x.x:53398] AH01075: Error dispatching request to : (polling)
and occasionally this error appears too:
[Wed Sep 06 09:13:33.296777 2017] [core:notice] [pid 10710:tid 140611211331392] AH00051: child pid 25582 exit signal Segmentation fault (11), possible coredump in /opt/bitnami/apache2
another occasional error (expected due to the multiple AH01075 timeout errors):
[Mon Sep 04 20:18:58.758718 2017] [mpm_event:error] [pid 19928:tid 140675798046528] AH00484: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
Stopping mysql server kills my site but seems to keep apache working fine, at least for an hour or two that i`ve been testing.
Is 457452 value is normal for mysqld.bin in the following process list? (ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS)
2128 /sbin/init
2400 php-fpm: master process (/opt/bitnami/php/etc/php-fpm.conf)
3840 -bash
4244 sshd: ubuntu [priv]
6928 /usr/bin/gonit
11036 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
11320 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
11364 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
11592 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
20592 /opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf -DDISABLE_BANNER
57668 php-fpm: pool wordpress
57716 php-fpm: pool wordpress
65252 php-fpm: pool wordpress
67608 php-fpm: pool wordpress
68776 php-fpm: pool wordpress
457452 /opt/bitnami/mysql/bin/mysqld.bin --defaults-file=/opt/bitnami/mysql/my.cnf --basedir=/opt/bi
PHP Version 5.6.30
mysql.bin Ver 14.14 Distrib 5.6.36
Ubuntu 14.04.5 (bitnami image on AWS)
Memory usage while apache not responding: used:883mb of 992mb
php.ini script memory_limit = 128M
Was a bit long to put it in a comment, so replying as an answer.
Are you logging any php errors? From what you presented so far, my theory would be that:
You used that script to do a search & replace of db but it executed poorly causing malformed or corrupted data.
That caused your php scripts that rely on mysql to go haywire due to malformed or corrupted data.
Because your php on fcgi isn't responding, your apache waits for it and holds onto the resources.
All the requests are hanging and now you run out of resources and start seg-faulting.
And then stupid apache, seeing that you're out of child count asks you to raise it not realizing you're already exhausted on physical resource beyond reason. Typical apache...
Because apache is now out of free children, it can't take anymore requests and it appears as if all of apache is broken even though it's merely clogged up by bad fcgi processes.
If my theory is correct, you should.
Check that none of the mysql data is corrupted
Check that the data that was replaced in mysql was as what you expected
Check for PHP error logs as they should be logging something if they can.
You should isolate the PHP processes that are actually the cause of clogging up and remove it if cleaning up data alone wasn't enough. Ideally, no matter how bad the data, the php program should've died cleanly.
Good luck hunting.

PHP Unable to retrieve large requests

I'm creating a service with php that returns json data from a table that contains 2100 rows. I'm using the following setup in dev:
Xampp with Apache and MySql
Windows 10
PHP-7.0.8
With PDO in php to execute the query
The service was working perfectly for both small requests (30 rows) and the entire table. I was calling it fairly often but had no problems. Recently it stopped working for requests that return the entire table and only works for the smaller requests.
I checked the Apache error logs and got the following:
[Sun Nov 20 11:06:06.687051 2016] [mpm_winnt:notice] [pid 4576:tid 536] AH00428: Parent: child process 11908 exited with status 1 -- Restarting.
[Sun Nov 20 11:06:06.889267 2016] [mpm_winnt:notice] [pid 4576:tid 536] AH00418: Parent: Created child process 924
[Sun Nov 20 11:06:07.415857 2016] [ssl:warn] [pid 924:tid 436] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sun Nov 20 11:06:07.442378 2016] [mpm_winnt:notice] [pid 924:tid 436] AH00354: Child: Starting 150 worker threads.
I have done a search for the solution although I am not sure what the issue is in order to search effectively. Each error message above appears to give me answers that do not relate to the issue I'm having (although, I'm not fully sure what the issue is).
Anyone know why something like this might happen?
My guess would be memory limitations (the children are being killed by the server). You can increase it but it won't solve the issue - what happens when you have 1 million records?
My advise is that you implement a pagination params and a max number of records to return:
http://website.com/api/v1/getUsers?position=0
http://website.com/api/v1/getUsers?position=100
http://website.com/api/v1/getUsers?position=200
etc..
This will drastically lower the stress on your system and enable the users to also lower their throughput in the event they only want the top x records, last 2, etc..
If you still want to be able to serve all, you can check this thread out to learn how to increase the memory for Apache: https://stackoverflow.com/a/36920556/1935500

Unexpected server reset with php and apache

I have an application which interacts with a database. Suddenly and occasionally, pages are showing me Server connection Reset error in my Web browser. More surpisingly, accessing on a localhost page is triggering an alert on avast.
If I refresh pages using Ctrl+R, it happens occasionally. PHP is not showing any error messages, and it seems like the server is taking more time to respond than usual.
I am using wamp with apache 2.4, PHP 5.4.3. I am clueless as to where to start debugging or where to the problem is.
[Sun May 13 13:01:14 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sun May 13 13:01:14 2012] [notice] Apache/2.2.22 (Win32) mod_ssl/2.2.22 OpenSSL/0.9.8x configured -- resuming normal operations
[Sun May 13 13:01:14 2012] [notice] Server built: May 13 2012 12:51:11
[Sun May 13 13:01:14 2012] [notice] Parent: Created child process 3660
Apache server interrupted...
arn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sun May 13 13:01:15 2012] [notice] Child 3660: Child process is running
[Sun May 13 13:01:15 2012] [notice] Child 3660: Acquired the start mutex.
[Sun May 13 13:01:15 2012] [notice] Child 3660: Starting 64 worker threads.
[Sun May 13 13:01:15 2012] [notice] Child 3660: Starting thread to listen on port 80.
[Sun May 13 13:01:15 2012] [notice] Child 3660: Starting thread to listen on port 80.
[Sun May 13 13:01:28 2012] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Sun May 13 13:01:28 2012] [notice] Child 3660: Exit event signaled. Child process is ending.
[Sun May 13 13:01:29 2012] [notice] Child 3660: Released the start mutex
[Sun May 13 13:01:30 2012] [notice] Child 3660: All worker threads have exited.
[Sun May 13 13:01:30 2012] [notice] Child 3660: Child process is exiting
[Sun May 13 13:01:30 2012] [notice] Parent: Child process exited successfully.
UPDATE:
When 'connection request' occurs if is use cachegrind it shows partial list of callstack of methods. means it does not run all the code. it is showing some require_once calls and that it. next time if i retry to get the page, page executes and shows the whole callstack.
When 'connection request occurs' it shows
18 different functions called in milliseconds (1 runs, 18 shown)
after retrying
220 different functions called in 329 milliseconds (2 runs, 220 shown)
I dont know why it is showing 2 runs. also it is taking more time to execute page. before it was doing it less than 100 ms.
Restart you computer and close/disable all running applications including anti-virus keeping only a minimal set of running applications. Close everything even those applications that you are sure can't interfere - you never know..
Make sure PHP shows all errors/warnings:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Make sure you review every warning you receive from PHP. It may give you a clue.
Try to isolate a problem. Comment a chunk of code you suspect to cause the problem. Keep commenting until stop receive the error. Then start uncommenting until you find a problematic place. This way you can isolate a problematic code and once you see it, you may understand the problem.
Add lots of statements that will write to log file (or just echo). Then you can analyze the log file and understand at which point error happens helping you to isolate the problem...
Eventually you will find the problematic code block and will be able to track the problem. Hopefully :)
to restart Apache via PHP use the follow code in PHP
exec('/etc/init.d/httpd graceful');
and also look in the manual... and change the path to your httpd
Change apache listen port from 80 to 8080
file httpd.conf , change listen 80 to listen 8080 and restart apache
Re-try disabling temporarly the antivirus
Maybe it is not a right solution, but why not just try other WAMP version or maybe setup your system clock correct?. And have you tried to run Apache in minimal configuration? You may disable all extensions and modules (inc php itself) and if web server will work as expected you may turn one by one you modules. I don't know about your environment but you may also try to change working threads number and other values to minimal. I bet it doesn't help but at least you'll try.
If you have mod_security enabled try disabling and see if the same happens.. sometimes you can have over vigilant mod_security that will just go to http fail (sometimes can be as simple as inserting data with an ampersand into the database) and won't write any error to the server logs making it hard to troubleshoot, sounds similar to what you're experiencing, I would disable mod_security re-start server and see if the behavior has stopped!
It looks like some other people have encountered the same issue using Wamp:
Have you gone through each of the points enumerated in this post belonging to the official forum:
http://forum.wampserver.com/read.php?2,67660
Are you sure you don't have an include/require loop ?
That kind of loop make PHP eat up too much memory and apache kill itself to avoid it.
Or maybe some kind of 404 loop error ...
That kind of loop can happen if you have 404 errors sometimes. Here is an example :
You have a layout with an image which is missing, so it triggers a 404 errors. To display the page, the 404 errors add the layout around the error page which contains the missing image, which triggers another 404 errors.
Hope that helps.

PHP maximum execution time

In my Plesk 11, PHP 5.4.7. Apache/2.4.3 system, when I make cron jobs I get this error from error.log file.
[Tue Mar 19 21:33:18 2013] [warn] [client 88.44.55.66] mod_fcgid: read data timeout in 45 seconds
[Tue Mar 19 21:33:18 2013] [error] [client 88.44.55.66] Premature end of script headers: index.php
So I checked for execution time with this:
echo ini_get('max_execution_time');
I got this value: 1560000
It doesn't seem a timeout problem but I get timeout error?
Answer for the future reference:
Edit /etc/httpd/conf.d/fcgid.conf file with vim.
Change FcgidIOTimeout 45 to FcgidIOTimeout 600.
Restart Apache.
Then Fast CGI timeout will be solved.
That's a mod_fcgid timeout, not a PHP timeout. Take a look at the mod_fcgid documentation to find out how to change it, especially at FcgidIOTimeout.
Cron scripts if build correctly should not be run through apache. Your error shows that you are running into a timeout set by mod_fcgi.
If you access it through http in your cronjob, then it will work as a webpage request and then it may be affected by apache timeout because apache is involved in the process. You can run the php script directly with an absolute path using php interpreter to bypass apache

Categories