RSS

How can we use PHP to access shared library functions?

06 Apr

PHP function dl()Loads a PHP extension at runtime

<?php
// Example loading an extension based on OS
if (!extension_loaded('svnlabs')) {
if (
strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
dl('php_svnlabs.dll');
} else {
dl('svnlabs.so');
}
}

// Or, the PHP_SHLIB_SUFFIX constant is available as of PHP 4.3.0
if (!extension_loaded('svnlabs')) {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefix . 'svnlabs.' . PHP_SHLIB_SUFFIX);
}
?>


We can use linux “nm” or “objdump” command to list symbols in object files…

# nm -C svnlabs.so
# objdump -s svnlabs.so

Advertisements
 

Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: