Frequent "Connection Timeout" errors on a shared server using PHP/MYSQL - php

I have a Drupal site on a shared web host, and it's getting a lot of connection errors. It's the first time I have seen so many connection timeout errors on a server. I'm thinking it's something in the configuration settings. Non-drupal parts of the site are not giving as many connection errors.
Since this hosting provider doesn't give me access to the php.ini file, I put one at my docroot to modify the lines that I thought would be causing this:
memory_limit = 128M
max_execution_time = 259200
set_time_limit = 30000
But it didn't work. There is no improvement in the frequency of the timeout errors. Does anyone have any other ideas about this type of error?
Thanks.

You can control the time limit on a script while your script is running. Add a called to set_time_limit near the top of your PHP pages to see if it helps.
Ideally you need to figure out what you actual limits are as defined by your host. A call to phpinfo() somewhere will let you see all the config settings that your server has in place.

Related

Wordpress/Godaddy - cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received

I have followed most of the questions here, tried changing memory_limit, upload_max_filesize, post_max_size, max_execution_time, max_input_time, through .htaccess and php.ini file, but I'm still getting the same error.
Upon asking Godaddy support they are simply giving a scripted response. Stating that there is a problem with your plugins, you should deactivate and see.
Currently, GoDaddy support suggested adding the following configuration in php.ini and deactivate the plugins and it will resolve.
memory_limit 5000M
upload_max_filesize 3000M
post_max_size 3000M
max_execution_time 3000
max_input_time 3000
But, this error is been from the time of a fresh WordPress installation. So, will deactivating all the plugins lead to resolutions?. Any suggestions??
Because of this, I'm getting connection timeouts and unable to take a backup through admin.
Also, I'm on shared hosting. Site - 247btl.com
After a lot of playing around with php settings, this error was solved with the following PHP settings:
max_execution_time = 30
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
upload_max_size = 32M
I believe the problem was due to max_execution_time settings. Most of the guides suggested to increase it to 1000 along with increasing memory_limit, but that would lead to long load time. Tried it on a hostinger hosted website as well and it seems to work very well.
try to update your WordPress to the latest version if not already done.
Then if the problem is still there, contact hosting company and ask the hosting support team check following
1. your server are running latest version of PHP and the cURL library.
increase the Server Memory Limits settings.
The cURL error can be a dns related issue. Your hosting company might need to switch dns configuration to OpenDNS : https://www.howtogeek.com/164981/how-to-switch-to-opendns-or-google-dns-to-speed-up-web-browsing/
Ask your host if there is some limitation with wp-cron, or if loopback is disabled.
Ask your host if there a firewall or security modules (e.g. mod_security ) that could block the outgoing cURL requests.
You can also install the Query Monitor plugin and check the status of the HTTP API Calls in the admin page where the error is displayed.
In my case this was caused by the plugin "Contact Form by BestWebSoft".
If you find yourself in the same situation you have to disable the plugin one by one and refresh the page /wp-admin/site-health.php to check if the error is still there.
As explained here Getting "An active PHP session was detected" critical warning in wordpress this is due to a plugin badly developed.
Be aware that this issue can be caused by the use of the php session_start function. We had an issue where a developer had written the following.
add_action('init', function ()
{
if (!session_id()) { session_start(); }
});
This will kill the loopback and also disrupt REST API communications. This results in the cURL error 28 mentioned above. Sometimes it is not a complicated reason for the failure.
For Hostinger go to your Hosting Dashboard, then open PHP configuration option from Advanced menu(see screenshot below)-
After that goto PHP Options tab(see screenshot below)-
Then, Scroll down and change the MAX Execution value to 300(see screenshot below). Here 300 = 5 minutes. And after changing the value save these settings and this problem will get solved.

Long delay to load PHP in IIS over fileshare

I have a new IIS 10 / Server 2019 server, which uses a SMB file share for app data. My problem is, for PHP sites there is a delay of about 2 minutes and 15 seconds for a simple "hello world" website to start. Even stranger, it does it on all sites with PHP 7.x, but not on 5.x unless it's a more complicated site like Mediawiki. It also only does it when loaded over the fileshare, which is otherwise quick to access. Once loaded the first time it runs quickly for about 3 min until whatever loaded process has to reload from scratch again. Using the error log, I can see that PHP loads the ini instantly and will complain about formatting errors and such right away, but the first line of a php page does not load until the last second. PHP xdebug also doesn't seem to note anything until the last second of loading.
It certainly seems like something is trying to resolve and timing out, but using //192.168.1.x doesn't work any better than //fileshare. I've poured through the php.ini looking for a culprit but can't find it. Any help is greatly appreciated!
The main settings I've messed with are the ones below with different combinations and ways of writing the path.
cgi.force_redirect = 0
cgi.fix_pathinfo = 1
fastcgi.impersonate = 1
fastcgi.logging = 0
track_errors = Off
soap.wsdl_cache_dir = C:\inetpub\php_temp
error_log = "C:\inetpub\php_errors\php_error73.txt"
upload_tmp_dir = C:\inetpub\php_temp
sys_temp_dir = C:\inetpub\php_temp
session.save_path = C:\inetpub\php_temp
Managed to trace it down to two odd culprits.
The main time out issue was:
user_ini.filename =
By default it's commented out in php.ini, so removing the semi colon disabled that feature which must have had trouble searching for ini files on the file share.
Second issue on 5.x seemed to be related to having the old mysql plugin enabled. Leaving it enabled didn't seem to matter on local disk, but having it enabled caused issues on the file share. I'm using mysqli in code, so no problem disabling it for me.

Apache throwing 500 after 30 seconds

I'm running Apache2 and PHP5 on a dedicated VPS.
I have a script that should finish anywhere from 20-50 seconds. It works just fine, but if it takes over 30 seconds due to the rows it selected, it instantly kills the script and says:
"Service Unavailable - The service is temporarily unavailable. Please try again later."
I have max_execution_time=60, max_input_time=60 and memory_limit=256M in my php.ini.
In apache2.conf, I have Timeout=300.
In the script itself, I'm also using set_time_limit(0);
ignore_user_abort(true);
ini_set('max_execution_time', 0);
ini_set('memory_limit', '512M');
No matter what I change the script dies anytime the loading takes over 30.00 seconds and nothing is appearing in any of my logs.
Any suggestions on what other settings to try?
This script is for internal use only and will eventually be running from command line, but I prefer to debug/test from the browser.
The error you listed: "Service Unavailable - The service is temporarily unavailable. Please try again later." doesn't sound like a 500 response, it sounds like a 503. Are you sure you are getting back a 500? The causes for a 503 would be different.
An internal server error. Check that all your directives are correct. If you have an .htaccess file, make sure you don't have any typos. Other than that, you can debug your script. You maybe changing a setting that triggers the error or conflicts with something else on the server.
Do you have Mod_Security or php-suhosin installed? Those might interfere with the default configurations.

Php script stops after long time and no error could be found on the error_log

Im running a long php script which handles large amounts of data.
The problem is that the script suddenly stops and no exception is thrown or could be found on the error_log.
I have set the display_errors and the error_logging to 1 in the .ini config file.
Few more details:
1) The scripts executes the 'file_get_contents' function for many times.
2) The scripts contains recursion when the file_get_contents fails.
Any help would be appriciated.
It might have hit the max execution time.
set_time_limit(0); // to increase the timelimit to infinity
Error loging configs are different depending on your hosting environment. I'd first verify that you're editing the right php.ini file. Take a look at your phpinfo output and make sure that those params are indeed set and check the path/file for where errors are being logged to. Sometimes it goes to the apache error log, other times it can be sent to a dedicated php log. Are you able to get any error output if you purposefully create a syntax error? You might also consider looking in your syslog to see if there's anything there.

Codeigniter - Blank screen when trying to retrieve 8500 records

I am trying to display a table which contains 8500 records, I am using the same controller/model functions as I have used throughout the site which all work fine.
On this page however, I just see a blank screen. Is this a known Issue with codeigniter? Is there a work around? I am totally stumped, my only option I guess is to split the table into sub tables?
I can show you my code if needed.
Thanks
Dan
When youget a blank screen it usually mean you've done something to receive a PHP error.
To see what that error is, check the php error log. I suspect that you've exceeded the maximuim allowed memory limit.
php_value memory_limit 256M
php_value display_errors 1
php_flag log_errors on
php_value error_log /some/path/on/the/box/you/have/acess/to.log
Below are the hard coded PHP ways to enable the settings, above this line are .htaccess directives you can set that will kick in for your whole app.
To make sure error reporting is turned on and you're displaying errors you can do..
ini_set('display_errors', 'On');
error_reporting(E_ALL);
To find out where your error log is make a test script to tell you.
die(ini_get('error_log'));
Make sure log_errors ini setting is enabled too in your php.ini file.
If it is indeed that you're exceeding the max allowed memory limit you can increase it by doing
ini_set(“memory_limit”,”256M”); // 256 megabytes
I recommend updating this in your php.ini file and restarting apache for the changes to kick in.
If your script is dealing with large amounts of data and it can take a while to run then you might also exceed the max_execution_time ini setting.
To see what it's currently set at, you can do
die(ini_get('max_execution_time'));
There is a nice PHP helper funciton to set this for you set_time_limit
set_time_limit(300); // Input in seconds, this is 5 minutes.
Hope this helps you get somewhere.
Your best bet is looking at your error log though.
Good luck.

Categories