Tuesday, July 6, 2010

Upgrading to PHP 5.3 ports on FreeBSD

Environment:
FreeBSD

php5-5.2.12         PHP Scripting Language
php5-curl-5.2.12    The curl shared extension for php
php5-dom-5.2.12     The dom shared extension for php
php5-gd-5.2.12      The gd shared extension for php
php5-iconv-5.2.12   The iconv shared extension for php
php5-mbstring-5.2.12 The mbstring shared extension for php
php5-mysql-5.2.12   The mysql shared extension for php
php5-openssl-5.2.12 The openssl shared extension for php
php5-pcre-5.2.12    The pcre shared extension for php
php5-pdo-5.2.12     The pdo shared extension for php
php5-pdo_mysql-5.2.12 The pdo_mysql shared extension for php
php5-session-5.2.12 The session shared extension for php
php5-simplexml-5.2.12 The simplexml shared extension for php
php5-spl-5.2.12     The spl shared extension for php
php5-xml-5.2.12     The xml shared extension for php
php5-xsl-5.2.12     The xsl shared extension for php
php5-zip-5.2.12     The zip shared extension for php
php5-zlib-5.2.12    The zlib shared extension for php
pecl-stem-1.5.0     A PECL extension which provides word stemming

Task:
Upgrade all ports to php5-5.3.2

  1. Some of the functions are deprecated in PHP 5.3. I had to replace all occurrences of split() with explode() or preg_split() and mysql_escape_string() with mysql_real_escape_string(). Note that mysql_real_escape_string() requires second parameter - DB connection.
  2. Attempt to upgrade ports with `portupgrade php5*` did not work. Some of the extensions do not exist anymore in PHP 5.3, and `pkgdb` was quite confused. I had to delete all php5 ports and then install them again.
  3. PHP 5.3 installed extensions into a new folder /usr/local/lib/php/20090626. My php.ini had reference to the old one, /usr/local/lib/php/20060613. Had to change that manually.
  4. pecl-stem-1.5.0 was not marked for upgrade (pkg_version). However, I had to rebuild it, because it was incompatible with the new PHP libraries.
  5. `php -i` complained about undefined timezone. I had to add date.timezone="America/New_York" to php.ini.
  6. I checked which extensions are now "included with PHP by default" (in docs on http://php.net and in /usr/ports/lang/php5-extensions.Makefile), and installed some of them, in addition to what I had before. There was also a nice "fileinfo" extension that I thought could be useful. Here is the list of extensions after upgrade:
php5-5.3.2_1        PHP Scripting Language
php5-ctype-5.3.2_1  The ctype shared extension for php
php5-curl-5.3.2_1   The curl shared extension for php
php5-dom-5.3.2_1    The dom shared extension for php
php5-filter-5.3.2_1 The filter shared extension for php
php5-gd-5.3.2_1     The gd shared extension for php
php5-hash-5.3.2_1   The hash shared extension for php
php5-iconv-5.3.2_1  The iconv shared extension for php
php5-json-5.3.2_1   The json shared extension for php
php5-mbstring-5.3.2_1 The mbstring shared extension for php
php5-mysql-5.3.2_1  The mysql shared extension for php
php5-openssl-5.3.2_1 The openssl shared extension for php
php5-pdo-5.3.2_1    The pdo shared extension for php
php5-pdo_mysql-5.3.2_1 The pdo_mysql shared extension for php
php5-session-5.3.2_1 The session shared extension for php
php5-simplexml-5.3.2_1 The simplexml shared extension for php
php5-xml-5.3.2_1    The xml shared extension for php
php5-xmlreader-5.3.2_1 The xmlreader shared extension for php
php5-xmlrpc-5.3.2_1 The xmlrpc shared extension for php
php5-xmlwriter-5.3.2_1 The xmlwriter shared extension for php
php5-xsl-5.3.2_1    The xsl shared extension for php
php5-zip-5.3.2_1    The zip shared extension for php
php5-zlib-5.3.2_1   The zlib shared extension for php
pecl-fileinfo-1.0.4 A PECL extension to retrieve info about files
pecl-stem-1.5.0     A PECL extension which provides word stemming
 

Monday, July 5, 2010

nmap "error MD2 is disabled" workaround

NOTE: this is NOT a solution. It's a quick workaround.

Environment:
FreeBSD 7.2-RELEASE

openssl-1.0.0_2 (installed)
nmap-5.21_1 (to be installed)

Symptoms:
# cd /usr/ports/security/nmap
# make
Error: .... error MD2 is disabled ....

Workaround:

Add to /etc/make.conf:
WITHOUT_SSL=yes

This worked for me because I did not need SSL support in nmap.

Tuesday, May 18, 2010

Log in to Facebook to personalize your experience with this social plugin

I was unable to click on any FaceBook [Like] button until I enabled 3rd party cookies in FireFox.

With 3rd party cookie disabled, a FaceBook login pop-up window appeared each time asking to "Log in to Facebook to personalize your experience with this social plugin". Entering login/password wouldn't help. The pop-up appeared again and again.

(Tested on iframe version of FaceBook plugin, but I think that JavaScript version needs cookie, too...)

Monday, May 10, 2010

Simply Accounting cannot connect to database / files read-only / connection timeout

Version:
SAGE Simply Accounting 2010 B

Symptoms:
"Simply" starts, opens the company selection dialog. After a company is selected, it displays an error message, which could be about "read-only" files or about "connection timeout" or "cannot connect to database".

Clarification about the error messages:
Their content changes depending on the stage of your "fight" with Windows and Simply.

What help did I get from Simply (program's "Help" and online Knowledge Base):
Simply says that the problem lies in .NET Framework (version 2! - KB looks very outdated)

Steps that were pretty useless:
  • Reinstalling .NET 3.5
  • Installing .NET 1.1
  • Attempt to install .NET 2 (does not work on Vista)
  • Reinstalling .NET 3.0 (tricky: has to be done via "OS Features" in Control Panel / Programs and Features)
  • Removing old versions of Simply
  • Attempt to install Simply over existing installation
  • Playing with read-only attributes of files and permissions
What helped:
  • Uninstall Simply completely
  • Download Simply from SAGE website (they give the latest release, so I did not need to upgrade to release "B" after installation)
  • Remove old folder containing unpacked installation files
  • Install, run and feel happy
What was the real reason:

Simply Accounting 2010 uses MySQL ODBC connector 3.51
A separate installation of MySQL, not related to Simply, was recently upgraded to 5.1, with ODBC connector 5.1. Old ODBC 3.51 was removed.......

Now both versions of ODBC are installed. Simply feels happy.

Thursday, May 6, 2010

PDO bug: exception caught but reappears in foreach() loop

I was experimenting with PDO/MySQL trying to see how a PHP code will behave with a single static DB connection, multiple connections but declared as "persistent", unbuffered MySQL queries and so on - and discovered a bug which I'd like to show here, because it took me a while to find any reference to it.
I tested it with PHP 5.2.13 under both UNIX and Windows.
Below is the code that demonstrates the problem, and two solutions/workarounds:

#
# PDO foreach exception bug
# Demonstration code
# Author: http://www.tiv.net
# 2010-05-06
#
# Note: same results will appear if using "while fetch()"
# instead of "foreach()" loop
#

print 'This code works OK (Exception is cleaned artificially)
';
$conn = new PDO( 'mysql:host=localhost', 'test', 'test' );
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$oRS = $conn->query( "select 'OK'" );
foreach ( $oRS as $row ) {
    try {
        $conn->query( 'Bogus SQL' );
    } catch (PDOException $e) {}
    if ( $conn->errorCode() !== '00000' ) {
        $conn->query( "select 'CLEAN_PDO_ERROR'" );
    }
print 'NO exception will be thrown.
';
}

print 'This code works OK (two separate connections)
';
$conn = new PDO( 'mysql:host=localhost', 'test', 'test' );
$conn2 = new PDO( 'mysql:host=localhost', 'test', 'test' );
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$oRS = $conn->query( "select 'OK'" );
foreach ( $oRS as $row ) {
    try {
        $conn2->query( 'Bogus SQL' );
    } catch (PDOException $e) {}
print 'NO exception will be thrown.
';
}


print 'This code throws unexpected exception in foreach
';
$conn = new PDO( 'mysql:host=localhost', 'test', 'test' );
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$oRS = $conn->query( "select 'OK'" );
foreach ( $oRS as $row ) {
    try {
        $conn->query( 'Bogus SQL' );
    } catch (PDOException $e) {}
print 'Exception will be thrown after this...
';
}
?>

My "final note" on using "article" websites for SEO

None of the test articles I submitted was recognized by Google as a link source (checked both in the "link:" search and in the Webmaster Tools).
Nobody came to the site through those links either.

Sunday, February 21, 2010

EzineArticles - the verdict

The verdict is "NOT GUILTY!" :-)

Here is what I discovered during my little research:
  • EzineArticles has a well-designed and carefully developed interface for submitting articles. Except for minor bugs, everything works.
  • Submitted articles go through several stages of approval, starting from an automatic validation to the human-operated analysis of the content. (Disclaimer: my account was new. I do not know if the same level of validation is applied to the established authors)
  • My attempts to submit a "just-for-links" article failed. My article was rejected 5 times, for various reasons, including the last one, which pointed out that the content was "not unique and not giving any new specific information to the readers". There was a policy about the links, too, so I could not "stuff" my text with the link spam.
  • When I finally made a "real thing" (proud of myself :-), the article has been accepted. All the links in the article body had the "nofollow" tag (that means "ignored by Google"). Only the link in Author Profile (the article footer) did not have "nofollow".
  • After one week, the content of my article could be found only on the EzineArticles site. Therefore I assume that there is no automatic distribution of the content to some "satellite" websites.
In my opinion, EzineArticles cannot be used as a place to get "easy links".