Archive for March, 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

Distance measurement between two locations on Earth in MatLab

Suppose, you need to calculate distance between two locations on Earth in kilometers. And suppose you know their geographical coordinates, i.e. [latitude, longitude]. In MatLab there is a function distance(lat1, lon1, lat2, lon2). It calculates distance between two points in angle units (in degrees there). So, you can calculate distance between two objects in angle units. Next you should to convert angle units into kilometers. Use for this distdim(angle,’deg’,’kilometers’) function.

For example you need to find distance between Minsk, Belarus (53.9, 27,5667 [53° 54′ 0″ N, 27° 34′ 0″ E]) and Caracas, Venezuela (10.5207, -66.9245 in [10° 31′ 14.52″ N, 66° 55′ 28.2″ W]).


>> distdim(distance(53.9, 27.5667, 10.5207, -66.9245),'deg','kilometers')

Result will be 9355.484 kilometers.

Wednesday, March 19th, 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