KP Solutions

Solutions for Day to Day Technical Problems

December 22, 2012
by Ketan Patel
0 comments

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,

Ketan

October 9, 2012
by Ketan Patel
1 Comment

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…

Cheers,

Ketan

 

October 8, 2012
by Ketan Patel
0 comments

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.

Cheers,

Ketan

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
0 comments

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: 'smtp.xxx.com'
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): imap.gmail.com
Outgoing mail (SMTP): smtp.gmail.com
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.

HTH,

Ketan

 

April 26, 2012
by Ketan Patel
0 comments

Commands To Check Server Performance and Stats

The command I normally have been using to check the server performance is the good-old ‘top’ command. Gives you a very good snapshot of the things going on in your server.

However, today when I issued the top command I found that the CPU load was around 16.23 but none of the processes were consuming as much of the CPU. Moreover, all the CPUs showed that they were 0% idle. This is strange, idle time is 0%, CPU average load is 16.23 whereas none of the processes were really consuming as much of the CPU. So where’s the problem and who’s causing it?

While I was searching on several forums for help, I found a nice blog post here and here that gives you a list of very good commands to check a variety of stats. You can read up full details in there, however, I would just list those commands in here for future reference. The commands of interest were:

  • mpstat
  • sar
  • ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10
  • iostat
  • vmstat

If you understand the purpose of each of the above command, then it would give you a very good understanding of what your server is undergoing at that very precise moment.

Oh and another command very useful was ‘watch -n1′. If you add ‘watch -n1′ to any of the above listed commands then you would be able to monitor the update to the output of those commands as ‘watch’ runs the command at specified time delay of 1 second.

By the way, at the end of doing the above exercise, I wasn’t able to find the processes or the reason why the CPU load was 16.23 average while each of the CPU was 0% idle. The server was responding fine with the requests and hence I left it alone. Didn’t find the root cause of the problem. I think that some how one of the variables on which top depends was some how messed up. Also, I was pretty sure that this problem will go away once I reboot the server, but I don’t want to reboot server without really having a need to.

Hope, this post would give you some insight in finding more details on performance and stats for your server. If it does or even if it doesn’t, please leave a comment below :)

September 14, 2011
by Ketan Patel
0 comments

Find Sizes of SubDirectories In One Command

Today, I was running out of disk space on my laptop; not quite unusual to happen. However, with this situation of out of disk, I had to get rid of the directories or files which are using most space and I no longer need.

Now, I can easily find the size of folder by issuing ‘du -skh <folder_name>’. But this gets tedious if you have 50 folders in one directory. I didn’t want to run same command fifty times. So, I had two options :

  1. Write a script
  2. Or find a command to take care of this situation
A one line command is way better than script any time for me. So, I cooked up an easy to use command:
find * -maxdepth 1 -exec du -skh {} \;

This one line command gave me the size and filename/foldername besides it. Exactly what I wanted. Hope this helps you!

Ketan

July 11, 2011
by Ketan Patel
2 Comments

SQL Error: 2006: MySQL server has gone away

So you got an error “SQL Error: 2006: MySQL server has gone away”. Like me if you were wondering where the heck did MySql go away. It was there when the script started.

Ok, I am gonna tell you that there’s a variable in your mysql configuration that is causing the MySql connection to timeout waiting idle. This could happen in the case, when you start the php script, make a mysql connection and then the script is doing some heavy processing, while the mysql connection made initially is sitting idle doing nothing. So in such cases, the MySql will check for the ‘wait_timeout’ variable setting and if the php script didn’t use the mysql connection for the ‘wait_timeout’ interval, the MySql will kill that connection and hence your script will get the ‘MySQL server has gone away’ error.

Solution to resolve this issue, two folds:

  1. If you make the MySQL connection, then you better use it. If you don’t want it then the resource needs to be released so others can use it.
  2. Else If you think that you need the connection and it is OK for it to sit idle for that time, then increase the value of ‘wait_timeout’ during runtime at the beginning of the script by issuing the SQL query ‘SET GLOBAL wait_timeout=60‘ in case you want to set it to 60 seconds and then restore it before you exit your script.

But, as always, if you increase the ‘wait_timeout’ value, check your server performance for another few days and see if there is any negative impact. If no impact then you are OK, but if there is then I would recommend Option 1.

Hope to help,

Ketan

May 5, 2011
by Ketan Patel
16 Comments

MySql Error#1005 – Can’t create table (errno: 121)

I have been MySql Workbench for a long time now and I recommend everyone to use it for their database design needs. Today, I was exporting the mysql database design to .sql file and then importing the sql to mysql server. I got the error

"#1005 - Can't create table 'XXX.xxxx' (errno: 121)". .

I scratched my head, hmmm…. Error #1005 is for foreign key constraint errors, checked the keys, column type and everything looked OK.

After about 10 minutes of fiddling around, I found that I had forgotten to make the foreign key constraint names unique for that particular table. If you are using InnoDB engine, then you need to make sure that all the foreign key constraint names are unique across the entire database and not just the table.

Hopefully, you may find my post helpful and save you some minutes or hours sometimes.

Cheers,
Ketan

December 25, 2010
by Ketan Patel
0 comments

Problem to Share Windows Media Center with PS3

If you, like me, want to share the media from your PC/Laptop with PS3 and were unsuccessful then this blog post will help you out.

Its quite simple and you don’t need to install any 3rd party software to do so. This post assumes you have Windows OS and the PC & PS3 are on same private network. It’s only 2 step process:

  1. On the PC with the media content, you will have to add all the folders with media to the Media Library.
  2. After you have added, then open up ‘Windows Media Player’ and you have to enable Automatically allow all devices and computers to have access to your media.

Once you have successfully followed the two steps above, visit your PS3 and make sure you have ‘Media Server Connection’ checked in ‘Settings’. After that, you should be able to see your PC-name and browse the media library.

As always, if this post helped you solve the problem, please leave a comment or donate if you will to keep me motivated.

Thanks,
Ketan