Home Archive RSS Login

I learned something new today

Load a PHP extension at runtime

Recently my hosting company did some upgrade to PHP and it messed up my Pritlog sites because they were using Sqlite. I had a chat with them and they could fix the issue. Later I realized that they only fixed the issue when the PHP application was running from the web. If it was from the command line (CLI), then this issue would still be there. Upon contacting them again, they were taking a lot of time to figure out the problem and fix it. This is when I started searching for an alternative solution to this problem.
 
I came across this PHP function called - "dl". Using this, you can dynamically load the required extension (provided it is available on your server) during runtime. You can refer to the page on the PHP website that talks about this function.
http://us3.php.net/dl
 
Here is a simple code that can be used to load the sqlite extension.
<?php
// Example loading an extension based on OS
if (!extension_loaded('sqlite')) {
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        dl('php_sqlite.dll');
    } else {
        dl('sqlite.so');
    }
}
?>
When I plugged this code into my script, it started running fine.
 

Author: Prit -  Date: 18 May 2009 17:34
Tags: programming,php -  Visits: 22038 -  No Comments




Comments

No comments posted yet!


Add Comment

Comment Form

 (Required)

 (Optional, will not be published)

 (Optional, format: http(s)://website.com)



 (smgxk5p)