学习使用简单的php

配置文件在:/etc/php5/$中,不同的模式含有自己的php.ini配置文件。php可以运行于多种模式:cgi、fastcgi、cli、web模块模式等4种;

 

我现在使用的模式是cli模式,这里进行一次测试。

 

 

 

 

在ubuntu下需要安装sudo apt-get install php5-dev

php应该是php5的链接。

 

修改config.m4文件:

 

my.php文件内容:

<?php
$br = (php_sapi_name() == "cli")? "":"<br>";

if(!extension_loaded('my')) {
    dl('my.' . PHP_SHLIB_SUFFIX);
}
$module = 'my';
$functions = get_extension_funcs($module);
echo "Functions available in the test extension:$br\n";
foreach($functions as $func) {
    echo $func."$br\n";
}
echo "$br\n";
$function = 'confirm_' . $module . '_compiled';
if (extension_loaded($module)) {
    $str = $function($module);
} else {
    $str = "Module $module is not compiled into PHP";
}
echo "$str\n";
?>

 

my_test.php文件内容:

<?php
    echo confirm_my_compiled('testmerlin');
?>

 

 

编辑/etc/php5/cli/php.ini文件,添加一行:

 

测试:

tf@ubuntu:~/swinstall/php-5.6.4/ext/my$ php my_test.php 
Congratulations! You have successfully modified ext/my/config.m4. Module testmerlin is now compiled into PHP.
tf@ubuntu:~/swinstall/php-5.6.4/ext/my$

 

posted @ 2014-12-31 11:49  Merlin-magic  阅读(169)  评论(0编辑  收藏  举报