KP Solutions

Solutions for Day to Day Technical Problems

December 10, 2014
by Ketan Patel

Nginx – php-fcgi – Upstream timed out (110 Connection Timed out) while reading response header

If you have been debugging the ‘upstream timed out (110: Connection timed out) while reading response header from upstream‘ error, then don’t panic. I have got a solution for you.

Just like you, I googled around several sites and found variety of hacks that were working around the problem but not really solving the root cause. I hate hacks as it doesn’t fix the problem, just hides the real problem. Moreover, hacks will come around to haunt you at a very critical time in life and stress you like HELL!

Alright, enough of preface…

The problem you are facing is that one of your script is not responding within 30 secs (or the timeout you set) in ‘fastcgi_read_timeout’ (nginx.conf). If you expect your script to process longer than 30secs or timeout, then just increase the time to match what you think should be fair value.

However, in my case, I know that the server script should finish its processing in less than 10 seconds. So I keep the timeout at 30 seconds. I got this error. After searching and digging, found out that one culprit script which was taking longer to execute in certain situation and bringing the entire site to halt. The culprit was an API call to external server. So I recommend from my experience now, that don’t ever have an external API call as if the external server is having issue, then you will have an issue and crash your site.

Very Bad Idea… Hence, never ever ever call an external script from the script that servers webpages. Instead use client php when needed.

Now your problem… How will you solve it? Just think for places in your code where the php script will go beyond its alloted timeout. And that’s where you will find the problem.

You need to find out that script which is taking longer than your configured timeout. Once you have found that script, just fix the root cause and voilla, you won’t see the dreaded 110 connection timeout error.



September 5, 2014
by Ketan Patel

SVN SSL handshake failed: SSL error: A TLS warning alert has been received

You have a SVN server which is hosted on Apache with SSH Support. Now when you are checking out the SVN repo to your local linux box, you get this weird error:

SSL handshake failed: SSL error: A TLS warning alert has been received

In Mac/Windows, you would be able to check out the repo without issue, but on linux – no, it simply doesn’t work. Now you would do few google searches and look at stack overflow, but nothing will shed you light. I spent about 2 hours fixing this issue and what it was!! You will know in a sec…

svn co

The above command gives you error. However, if your SSL certificate is created using a host name, then the ip address will not work in the URL. You have to change the url to match your SSL host name (must be same in ssl.conf in httpd/conf.d and SSL cerficate)

svn co

Now it will work. Bloody hell! it’s just plain idiotic. Hope this helps.

Ketan Patel

October 7, 2013
by Ketan Patel

Load Data Infile Causes SQLState 28000: Invalid authorization specification

If you are using Load Data Infile and you get the error

SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied for user

This is an error where the database user that is used for database connection is missing a permission required to execute ‘LOAD DATA INFILE’ command. The missing permission is ‘FILE’ previlege. To issue the ‘FILE’ permission you issue following command using ‘root’ mysql user for the database user (for eg. ‘kpsolution’) .

GRANT FILE ON * . * TO ‘kpsolution’@’localhost’;

Once the database user (‘kpsolution’ in our case) is granted the ‘FILE’ permission, you will be able to execute the ‘LOAD DATA INFILE’ command without issue.

Let me know if you encounter any issues and I will definitely give it a try to resolve your issue.

Ketan Patel

September 4, 2013
by Ketan Patel

is_file and file_exists fail with symbolic links

Recently, I came across an issue where is_file and file_exists would fail in case of file with symbolic links.

Let’s say I have a file at /home/kpsolu2/personal/images/rome.jpg and I do a symbolic link from another user /home/kpsolu3/public_html/images/rome.jpg as follows:

ln -s  /home/kpsolu2/personal/images/rome.jpg /home/kpsolu3/public_html/images/rome.jpg

Now, since this symbolic link is from one user’s account to another user’s account, you need to give proper permissions. I don’t advise this architecture, but there were reasons for which I had to do it this way. So let’s continue. I added kpsolu2 usergroup to user kpsolu3 using following command

usermod -a -G kpsolu2 kpsolu3

Now, I was able to do

ls -l /home/kpsolu3/public_html/images/rome.jpg

and get valid listing. But, in php, if i do

if ( is_file (‘/home/kpsolu3/public_html/images/rome.jpg’) )

I always get that file is not valid. So luckily, it struck in my mind, let me check my server settings for ‘mod_rewrite’ for the account ‘kpsolu3’. I found the reason why this issue occured.

 Options +SymLinksIfOwnerMatch

I had above setting, which forced web server that serve files only if owners matched but the owner was ‘kpsolu2’ and not ‘kpsolu3’. Hence to patch the things, I changed the setting in httpd.conf file from above to below:

Options +FollowSymlinks

Restarted the server and the code then started to work as is. I know this brings in complications and security issues, but the situation demanded it and I had to fix it. So there you go.

If this post helped you in any way or you have any questions then let me know via Comments below.

August 18, 2013
by Ketan Patel

Windows PHP with fcgi PHP_SELF invalid issue

Recently, I upgraded my laptop and I had to do a clean install. I decided to use PHP in fcgi mode instead of the regular module mode with Apache. With FCGI, there are obvious advantages. However, one disadvantage I found was that it required a lot of tweaking to get it done right.

Well, after been tweaked and ready for use, fcgi gave me a weird error where ‘PHP_SELF’ environment variable had wrong value. I had my apache root as “C:\server\www” and the PHP_SELF environment variable would have “C:\my_site\index.php”. This made absolutely no sense. I expected the PHP_SELF variable to be “C:\server\www\my_site\index.php”.

Considering the absurd behavior of php, I started digging into the the fcgi parameters and found that a param named “FcgidFixPathinfo” was the culprit. Initially, I had ‘FcgidFixPathinfo’ as ‘1’ and the paths were getting messed up. I changed it to ‘0’ and the paths were fixed.

Hence, ‘FcgidFixPathinfo’ param is not fixing the params, it is actually messing up the path. I wonder why would you need this variable. But nonetheless, if some one runs into this situation, hopefully he/she would find this post via Google before wasting an hour like me 🙂

Hope that helps.

Ketan Patel

December 22, 2012
by Ketan Patel

php createimagefromjpeg fails without error

I guess you have an issue while you try to create thumbnail from a jpg, merge two jpgs or crop a jpg. Issue is that @createimagefromjpg fails without any reason on a code like this

$srcImage = @createimagefromjpeg($filePath);

Now, if you look up php documentation for error control, you would see that ‘@’ sign is culprit. It suppresses all the warnings and errors. Don’t use it unless you are 100% sure that you don’t want any errors from it. I found out that since ‘@’ sign was there, I didn’t see any errors in any of my logs. Now, once I removed the ‘@’ from ‘@createimagefromjpeg($filePath)’, I saw exact error why the script wasn’t able to process the jpg.

Most of the time the error would be one of the following:

  1. Source image file not found
  2. Memory limit is too low to process the image
  3. GD library support is not built in the php executable on your server.

Once, you know what error is, you can take an appropriate action to resolve it.

Like me, if you are using an open source library, sometimes it takes lot of pain to resolve a minor issue. First, thing to ensure is that if you see any of those ‘@’ char in front of any failing line, then remove it.

I recommend to avoid using ‘@’ char to suppress errors/warnings.

Hope to help,


October 9, 2012
by Ketan Patel

Zend Debugger Loading Wrong File While Debugging

I spent about 1 hour figuring out this issue. It was a pain and for no apparent reason, all of a sudden Zend Studio Debugger started to load up wrong file in an include statement, even though the path was specified. The script would work OK if ran without remote debugging, but with Zend Studio Debugger, I got this issue where a wrong file got included instead of a file that should get included.

I put in all debug logs and nothing came up. I was frustrated and I left work for lunch. Then, when I came back I thought that somehow internal path would have got messed up in Zend Studio Settings. There it was — the culprit — wrong path mapping…. As soon as I removed all the path mapping in the php server, issue got resolved.

So for you to resolve your issue, you go to ‘Windows’ -> ‘Preferences’ -> ‘PHP’ -> ‘PHP Servers’ -> Select ‘Default PHP Web Server’ and hit ‘Edit’ and then you click on ‘Path Mapping’ tab. Remove all entries there. I didn’t need any of those, so I removed all of those.

Now you start the debugging session and you should be good to go. Hope this helps ya…




October 8, 2012
by Ketan Patel

MySQL #1005 – Can’t create table (errno: 150)

Like me, if you got the message “#1005 – Can’t create table (errno: 150)” when creating a new table, then chances are that Google Search gave you information that this is a foreign key constraint error. You go back, look at your SQL to create table and you think the relation is perfectly fine. Not sure, why this would give me an error. In this case, this post will address your issue.

Assuming that the foreign key definition is correct, when you get the error 150 while creating a foreign key constraint, there is a subtle knowledge needed. And this knowledge is that both tables in the constraint, must be using same Storage Engine. If one table is using MyISAM and another using InnoDB, then you would get above error. So, always make sure that both tables in a RDMS Foreign Key are using same Storage Engine.

Hope this post helped you and if it did, then please make sure to leave a comment.



September 27, 2012
by Ketan Patel
1 Comment

CakePHP Test Failure with Error PHPUnit_Framework_AssertionFailedError::getComparisonFailure()

If you are using CakePHP 2.2 and are developing code with unit testing, then chances are you have stumbled on the error “Fatal error: Call to undefined method PHPUnit_Framework_AssertionFailedError::getComparisonFailure() in E:\…\lib\Cake\TestSuite\Reporter\CakeHtmlReporter.php on line 252” with no real useful message.

Default test Case pushed out Cake Baking system has just two methods setup and teardown. So if your test file doesn’t have any test methods then this error will come up. So to fix it, add a test case and the error will go away.

For eg. if you are looking to test your Model ‘User’ and there’s no test case in the UserTest.php file, then you would get above error. To fix it, add ‘public function testUser() { }’. This will fix that error and then you can start creating proper test cases.

June 30, 2012
by Ketan Patel

Socket Error 10060 – The Connection to the server has failed

So, you setup an email client with new email account and when you try to send an email, you get an error that says:

The connection to the server has failed.
Subject: 'XX.....'
Server: ''
Protocol: SMTP
Port: XXX
Secure(SSL): Yes
Socket Error: 10060

When you get this message, your email client is telling you that there is a configuration issue for the email account in question.

Check your outgoing email settings and that’s where you would find the problem. For me the problem was the Outgoing SMTP port. I changed to correct port and the email was sent successfully.

In case if you are using Google Apps for your email, then the settings that you need to use are (Windows Mail, Outlook settings):

In Servers Tab:
Incoming mail (IMAP):
Outgoing mail (SMTP):
Select 'Log on using clear text authentication'
Select 'My server requires authentication' under 'Outgoing Mail Server'

In Advanced Tab:
Outgoing mail (SMTP): 465
Incoming mail (IMAP): 993
Select both checkbox: 'This server requires a secure connection (SSL)'

Hope this comes in handy to whoever has this problem.