Posts tagged: php


Using the following curl block I was getting an unexpected response from the server.

$ch = curl_init($post_url);
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, "orderXML=".$xmlRequest );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 3000 );
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
$xmlResponse = curl_exec( $ch );

Pretty simple call. It’s attempting to communicate with an url over https which is where the problem lies. Here is the response I was receiving.

Curl error number: 35
Curl error: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

Simple call. Confusing problem. Simple solution. Add the following line before the curl_exec.

curl_setopt($ch, CURLOPT_SSLVERSION, 1);

Checking the documentation, it says this: CURLOPT_SSLVERSION – The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually.

I tried setting the value to 2 but it didn’t work.

Curl error number: 4
Curl error: OpenSSL was built without SSLv2 support

And setting it to 3 didn’t either.

Curl error number: 35
Curl error: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

I wish I could tell you why setting it to 1 worked for me, but I don’t understand it. It just works for me where the documented values do not.

SQLite and PHP5 in LAMP

It seems that most articles written about SQLite and PHP are at least two years old and might leave some feeling like they are outdated and do not work. Here’s something recently dated (relatively speaking, assuming you’re reading this in 2008).

This article will help you get sqlite working with a directory hosted in your /home that is symlinked to /var/www

Using your favorite package manager, install a LAMP (Linux, Apache, MySQL, Perl) server. Ignore the fact that you are installing M (for MySQL).

Next, use the package manager to install php5-sqlite (NOTE: this is assuming that your package manager installs PHP5 by default)

Restart the apache webserver

sudo /etc/init.d/apache2 restart

And now php5-sqlite should be playing nice with apache.

At this point, I ran into trouble. I couldn’t get any examples of sqlite within PHP to work properly. The problem: permissions.

Create the directory that will host the files.

mkdir ~/mytest

Change the group permission from your username to www-data

sudo chgrp www-data ~/mytest

Create the symlink to the web directory

sudo ln -s ~/mytest /var/www/mytest

Rejoice in an sqlite-capable directory (specifically located at http://localhost/mytest). Give it a test with the example here (but in this example remove the “unsigned” part of “unsigned primary key” first) or here.

Staypressed theme by Themocracy