Archive

Posts Tagged ‘php’

OpenSSL Error in PHP

December 7, 2009 1 comment

I decided to play with Swiftmailer, the successor to phpMailer, but wanted to try something different — I wanted to use TLS. I was trying to setup a piece of test code for an internal project and just couldn’t get it to work in the office so I decided to try it from home as I had fewer variables to trip me up, i.e. no firewalls or hardened mail servers to play with.

I installed XAMPP v1.7.2 on my Windows PC which gave me PHP v5.3.0 with OpenSSL v0.9.8k. It also gave me TLS support as ‘Registered Stream Socket Transports’ on the PHPINFO() page said I had ‘tcp, udp, ssl, sslv3, sslv2, tls’ available. I then used a simple piece of code:

require_once 'lib/swift_required.php';

// Setup the mail transport
$transport = Swift_SmtpTransport::newInstance ('smtp.gmail.com', 587, 'tls');
$transport->setUsername ('{username}@gmail.com');
$transport->setPassword ('{password}');

// Setup the mailer
$mailer = Swift_Mailer::newInstance ($transport);

// Build the message
$message = Swift_Message::newInstance();
$message->setSubject ('Testing');
$message->setFrom (array('{username}@gmail.com' => 'Test Sender'));
$message->setTo (array('{email address}' => 'Test Recipient'));
$message->setBody ('Here is the test message.');

//Send the message
$result = $mailer->send ($message);

You’ll have to change the {username}, {password} and {email address} though to make it work for you. And then I ran it.

BANG! — It failed with a cryptic error message “SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number”.

I Googled for an hour and found post after post but I got it in the end. It appears to be a version difference between the client and server, the PHP code is running SSL v3 whereas Google Mail is looking for SSL v2. If I changed the port from 587 to 465 it all went away though.

BTW The other tool I used to play with TLS was SendEmail, a command-line utility for sending emails. The following command worked perfectly for me on port 587 (annoyingly). It all needs to be on one line.

sendemail -f {username}@gmail.com -t {email address} -u Testing
-m "This is a test message." -s smtp.gmail.com:587 
-xu {username}@gmail.com -xp {password} -o tls=yes
Advertisements

Upgrading from Kohana v2.3.3 to v2.3.4

August 15, 2009 Leave a comment

I just found the official Kohana documentation for upgrading your Kohana applications to the latest version. In fact, these instructions also work for upgrading Kohana v2.3.4 to v2.4 and Kohana v2.x to v3.x.

Upgrading your Kohana Application

Read the source code, note differences in the available methods and properties. For more detailed information, please refer to the change log.

Change Log

The official Kohana change log may be obtained by using diff, or the Windows equivalent, against the old and new versions. Please enjoy using Kohana!

As one of the lead developers proudly proclaims – “We try to be an advanced framework for developers who know what they are doing when it comes to programming. The framework should not hold the developer’s hand.” He also thinks people complain when new versions are released and says it’s because “they’re stuck in the past” even though he was recently threatening to fork the project because his v2.x branch was in danger of not seeing the light of day due to the new v3.x branch.

My recommendation is that you should just use a single version of Kohana for your application and not worry about the future as it’s uncertain and likely to be a complete waste of effort upgrading.

Categories: Uncategorized Tags: , , , ,

Kohana – The Leet Framework

August 15, 2009 1 comment

When I started messing around with Kohana, I was impressed. It met my needs, fitted in with my level of programming knowledge and saved me a lot of time writing my own library of code, or my own framework. However, I think I misunderstood the objectives of the development team.

They seem to want to promote Kohana as a better version of CodeIgniter with loftier goals, mainly that it’s based on PHP v5 and that it’s not guided by an evil corporation. However, mainstream products come with a price tag, you need to sell it. For any code library, that means a slick site, easy to access API and high-quality documentation. CodeIgniter has this, so does CakePHP, Symfony, Zend Framework and other high profile open source libraries such as jQuery and Prototype. If Microsoft has taught programmers anything, it should be that marketing wins, not the quality of code. Most of Microsoft’s software is so-so but the interface is usually very well engineered and the marketing machinery is superb. Together they’ve managed to eliminate many pieces of better software.

Kohana seems to be at a crossroads today. Do they pursue the mainstream; gain wider adoption, more users, more money and become more competitive OR do they stick with their niche product and keep telling people to read the source code? Either way is good for me, I’m sure I’ll stick with the product until it dies, gets forked and renamed. I’ll just stop saying nice things about it and stop doing my bit to try and help out, ease the woes of newbies and tell them to go somewhere else.

I just wish the project had better management at the top and knew where it was going, rather than just ambling along at the will of the lead developers. It almost seems that Kohana is what it is and if it works for you, good. If it doesn’t, there are plenty of other frameworks out there.

Kohana vs Cake vs Zend vs CodeIgniter vs Symfony

August 12, 2009 12 comments

A popular question asked all over the internet is – “Which PHP framework should I choose?”. The likely candidates are Kohana, Cake, Zend, CodeIgniter and Symfony. There’s a very simple answer.

Read more…

Why Choose Kohana?

July 17, 2009 Leave a comment

It’s no secret that I’ve been struggling with Kohana over the past few weeks as I’ve been building a new site for a non-profit in Vancouver, BC.

You may want to read my web development background for more information about my development path and how I got to this current project.

Although I’ve been programming in PHP for a decade or so I’ve learned the limitations of the language and started building up a reportoire of code modules and drop-in classes. The first one I wrote was an error handler as v4 was hopeless. My class would intercept the errors, log them, show them in development but not production, and would even dump the source around the problematic line.

Read more…

When LESS Becomes More – Leaner CSS

June 22, 2009 1 comment

I came across LESS the other day and thought nice. I then came across it again and re-read it in more detail and thought how easy this is to achieve in PHP.

Read more…

Categories: Uncategorized Tags: , , , , , ,

Indent/Bracketing Style

June 10, 2009 Leave a comment

It seems one of the guaranteed ways of starting a war between geeks is to push one style of bracketing over another. The main battle is typically between Allman and KNF. See Indent Style on Wikipedia for more background.
Read more…

Categories: Uncategorized Tags: , ,