How can we use PHP to access shared library functions?
On April 6, 2010,
in Amazon Cloud EC2 S3, CentOS, Fedora, Linux, Open Source, Tips, Tricks,
by phpsolutions
PHP function dl() – Loads a PHP extension at runtime
<?php
// Example loading an extension based on OS
if (!extension_loaded('phpsolutions')) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
dl('php_phpsolutions.dll');
} else {
dl('phpsolutions.so');
}
}
// Or, the PHP_SHLIB_SUFFIX constant is available as of PHP 4.3.0
if (!extension_loaded('phpsolutions')) {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefix . 'phpsolutions.' . PHP_SHLIB_SUFFIX);
}
?>
We can use linux “nm” or “objdump” command to list symbols in object files…
# nm -C phpsolutions.so
# objdump -s phpsolutions.so
Tagged with: dl in php • dll in php • list shared library object • nm in linux • objdump • shared library functions • so in php
2 Responses to How can we use PHP to access shared library functions?
Leave a Reply Cancel reply
You must be logged in to post a comment.
This site uses Akismet to reduce spam. Learn how your comment data is processed.
To be sure along with your thoughts here and that i really like your website! I’ve bookmarked it to ensure that I’m able to revisit & read more down the road.
Hey! Wanted to leave a comment. I must say i enjoyed reading this article. Carry on the awesome effort.