How can we use PHP to access shared library functions?

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

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch