Thursday, September 16, 2010

File upload Form, CakePHP and IE6

Don't ask me why, please tell me why...

A new bug I couldn't explain with Internet Explorer 6 : In my CakePHP controller, after a form submit, a simple redirection doesn't work (unable access to server). I have to use the third parameter of AppController::redirect method as following :

$this->redirect(array('action'=>'myAction'), null, false);

This 3rd parameter with "false" makes php engine not to exit from script after redirection.

Thursday, September 9, 2010

CakePHP, MySQL and tinyint(1)

Have you ever tried to set a greater than 1 integer in a tinyint(1) field with CakePHP ?

Impossible !

CakePHP handles tinyint(1) like boolean ! So, use tinyint(1) fields only for boolean with CakePHP !

Wednesday, February 10, 2010

Bug PDO MySQL 5.0.67 (Linux only)

My configuration :

  • - CentOS 5 (same problem with RedHat)
  • - MySQL 5.0.67
  • - PHP 5.1.6
  • - PDO lib 5.0.67

I may encounter such fatal errors :

Fatal error: Call to a member function fetch() on a non-object...

It looks like the PDO Statement has been killed or doesn't respond... For the same processing, running on Windows, with MySQL 5.1.30 and PDO lib 5.0.51a, everything works...
When I execute code on Windows server, targetting database to my Linux server, it works well. So I can rely on MySQL server...
Using a mysql_connect() command also works, so I guess the problem comes from PDO libraries...

A very few people mentionned this issues on technical forums that's why I open this post to anyone who's been annoyed with it...



Updated on 2010-03-01

Here is a solution :

$queryTypRef = myQuery;
$stmtTypeRef = $this->_dbOps->query($queryTypRef);
$resTypeRef = $stmtTypeRef->fetch();

$stmtTypeRef->closeCursor();
$stmtTypeRef = null;

Monday, February 8, 2010

Performance measures

How to introduce performance measures in your logging system ?


An easy way to measure response time is to use microtime() function.

PHP official documentation :
microtime() returns the current Unix timestamp with microseconds. This function is only available on operating systems that support the gettimeofday() system call.

In order to measure a response time of a request, you have to identify its entry point. Then put the Start top as the first action. Finally, detect the request response point and put the Final top just above...

//Launch timer
$time0 = microtime(TRUE);
$time00 = $time0;
echo 'Call: '.$time00.' - TIMER Request toto - Start : '.$time0.'<br/>';

//Response initialization
$response = 'Here is the final response to client !';

//some actions
usleep(100000);

//some intermediate measure
$timeX = microtime(TRUE);
$timeXDuration = $timeX - $time0;
echo 'Call: '.$time00.' - TIMER Request toto - Intermediate X : '.$timeX.'<br/>';
echo 'Call: '.$time00.' - TIMER Request toto - Intermediate X Duration : '.$timeXDuration.'<br/>';

//Stop timer
$timeResponse = microtime(TRUE);
$timeDuration = $timeResponse - $time0;
echo 'Call: '.$time00.' - TIMER Request toto - Response time : '.$timeResponse.'<br/>';
echo 'Call: '.$time00.' - TIMER Request toto - Duration : '.$timeDuration.'<br/>';

return $response;

This code displays :

Call: 1265645157.8705 - TIMER Request toto - Start : 1265645157.8705
Call: 1265645157.8705 - TIMER Request toto - Intermediate X : 1265645157.9706
Call: 1265645157.8705 - TIMER Request toto - Intermediate X Duration : 0.10011100769043
Call: 1265645157.8705 - TIMER Request toto - Response time : 1265645157.9707
Call: 1265645157.8705 - TIMER Request toto - Duration : 0.10015106201172

Note that $time00 is used to identify the call. It could be replaced by a random string, and you can pass it as a parameter to sub-functions to measure sub-treatments...

Tuesday, January 12, 2010

SoapClient proxy port

When you configure a proxy to access a web service, you must specify 2 parameters : proxy_host and proxy_port.

Note that proxy_port value must be an integer. That seems obvious but problematic if you dynamically load application parameters as constants from a database.

$options = array( 'proxy_host' => PROXY_HOST,
                  'proxy_port' => intval(PROXY_PORT));
$client = new SoapClient( "some.wsdl", $options);