Not working HTTPS queries with Curl

If you can work with usual http queries using PHP Curl, but have problems with https you can try to include this option:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

Tuesday, July 22nd, 2008

URL file-access problems in PHP

For many hosting providers it’s standart to disable URL file access. So, if your PHP code has file_get_contents(), require(), require_once(), include() or include_once() commands with some URL as a parameter, you will receive an error message: ‘URL file-access is disabled in the server configuration’.

To avoid this error you can try to use CURL.

Instead of this command:

$content = file_get_contents('http://sample_url');

You should use:

$ch = curl_init();
$timeout = 3;
curl_setopt ($ch, CURLOPT_URL, 'http://sample_url');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$content = curl_exec($ch);

Sunday, March 30th, 2008

Translating symfony validator yaml configs with xgettext

Previously I wrote how to automate routine translation work with xgettext for symfony framework. Unfortunately xgettext cannot parse YAML configs. Obviously you’ll need to translate at least validator error messages. rgettext is not capable too.

I found some solution but I didn’t like it. I wanted to use PoEdit tool to have possibility for automated translation, syncing with sources and easy interface. So I wrote modified task which looks for all validation configs and creates fake php files with messages, which can be parsed by xgettext.

Usage is simple, just copy attached file to symfony/data/tasks in your PEAR directory and run symfony i18n-fake-php app_name. PHP files will be created in validate/ directories. After that you can use xgettext.


Sunday, March 9th, 2008

Rsync using checksum in Symfony

Symfony framework allows easy deployment of the project. All you need to deploy using rsync – is to type symfony sync production (add go to the command for real deploying). It takes connection parameters from config/properties.ini.

However it is using files comparison by size and modification date, default for rsync utility. It isn’t in symfony documentation, but you can easily change rsync parameters to whatever.

Default parameters symfony uses are -azC --exclude-from=config/rsync_exclude.txt --force --delete. To use checksum comparison add the line to [production] in properties.ini:

parameters="-azC --exclude-from=config/rsync_exclude.txt --force --delete --checksum"

Wednesday, March 5th, 2008

Form-building components for Joomla

Recently I was creating contact form for one Joomla-based site. It was a standard contact form, everybody did similar hundred of times. But this time I decided to use one of existing components for building forms. There was one commercial, but it wasn’t the case, I didn’t even give it a try.

First one I tried was FacileForms. I just picked up the first one in rating. Well, my first impression was positive. There was everything I needed. Component has a lot of examples and Javascript library. I spent about an hour building my form (there was quite a lot of fields). Finally it was done, I opened frontend for last time.. Fuck. All form elements were absolutely positioned with coordinates I gave through admin. Did you ever heard about absolutely positioned form? I don’t. I decided that it was my mistake or lack of documentation, so I dived into sources. Fuck.
$attribs = 'position:absolute;';. I throw it away. You can do the same or make a code contribution. I didn’t have a time.

Second component was ArtForms. It was much better for my needs, it has customizable template for each form element. And it has nice ajax-based admin, which is much more convenient for editing. But it has disadvantages too. When you create input elements you cannot assing “name” property to them. I could live with it so I stopped my searches.

Friday, February 15th, 2008