petek, 25. maj 2012

connect to oracle

Let say we need to connect to Oracle DB form our windows (64 bit) php server. Linux fan boy would think tkat apt-get php module (on windows most modules are shipped with php installation ) and uncomment form php.ini would do the trick - but not with windows and oracle.

uncomment this line


extension=c:/php54/ext/php_oci8_11g.dll  ; Use with Oracle 11gR2 Instant Client

will probably give u some sort of error

[Fri May 25 09:09:03 2012] [error] [client 192.168.1.194] PHP Warning:  PHP Startup: Unable to load dynamic library 'c:/php54/ext/php_oci8_11g.dll' - %1 is not a valid Win32 application.\r

due fact this extension needs oracle client to be installed as well. So next step would be installing of proper (32bit!) oracle client form http://www.oracle.com/technetwork/topics/winsoft-085727.html (i usually go for smallest package in this case *Instant Client Package - Basic Lite: Smaller version of the Basic, with only English error messages and Unicode, ASCII, and Western European character set support (10.2 only) )

After that we need to put the installation folder to path variable


After apache  restart phpinfo() should output some oci output


The following example will test the connection and do some trivial query

<?php
$c = oci_connect('*username*', '*password*', '//192.168.1.113:1521/ORCL');
$sql  = "SELECT ID, USERNAME FROM USERS";
$stmt = oci_parse($c, $sql);
oci_execute($stmt, OCI_DEFAULT);

 while ($row = oci_fetch_array($stmt, OCI_ASSOC)) {
    print_r($row);
}

sreda, 16. maj 2012

debug PHP the JS way

We use CI (http://codeigniter.com/) in almost all our projects and since in JS got console.log our PHP debug/output was lagging behind with it's own print_r. Every good thing is eventually dumped by another new good thing so after lookin around for debug solutions in PHP and the fact, we almost all time share browser screen with firebug window FirePHP (http://www.firephp.org/) was the reasonable path.

For installation we just need to copy all files form archive to /ci/application/libraries/firephp_library and wrapper class looks something like

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require "firephp_library/FirePHP.class.php";
class Firephp_library extends FirePHP {
    function __construct() {
    parent::init();
}
}

After that we can use it in controller:

//load library
$this->load->library('Firephp_library');

Then i took it for a test drive...




nedelja, 13. maj 2012

Stuck in the moment

Sometimes php-cgi.exe process get stuck -- and eventually over some period of time, when number of prcesses get over critical point (i don't have clue what would that be) whole apache-php stack freezes.
That happened around once per month, but it is still unpleasant experience. Someone needed to log into server stop apache kill all php-cgi.exe processes and restart apache.



After a bit googling we write a tiny script and schedule it once a day to kill all php-cgi.exe processes so now can spawn and since than no more incidents like this occurred anymore - not bad (i know if someone process is in the middle of work it gets killed but its small price to pay)

C:\WINDOWS\system32\taskkill.exe /IM php-cgi.exe /F