How can we use PHP to access shared library functions?
On April 6, 2010,
in Amazon Cloud EC2 S3, CentOS, Fedora, LAMP, Linux, Open Source, Tips, Tricks,
by Sandeep Verma
Hits: 199
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
Other Posts
About the author
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
Tagged with: dl in php • dll in php • list shared library object • nm in linux • objdump • shared library functions • so in php












