Berkeley 5.0.21提供的PHP扩展的Bug
今天装了个Berkeley 5.0.21进行测试。
顺利编译了自带的php_db4模块后,进行测试。发现del操作报错:
illegal flag specified to DB->del
<?php
dl('db4.so');
$db = new Db4();
$db->open(null, 'info.db', 'info');
$db->put('key', 'value');
var_dump($db->del('key'));
$db->close();
$db->del的返回值是22。也就是参数错误。
之前没接触过BDB,也不知道正不正常。但怀疑是不是因为php是支持4.x系列的,因此进到php模块的代码看了一下。
php的del的实现很简单:
/* {{{ proto bool DB4::del(string $key [, object $txn])
*/
ZEND_NAMED_FUNCTION(_wrap_db_del)
{
DB *db = NULL;
DB_TXN *txn = NULL;
zval *txn_obj = NULL;
u_int32_t flags; // 出错行:未初始化!改为 u_int32_t flags = 0;
DBT key;
char *keyname;
int keylen;
getDbfromThis(db);
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|O", &keyname, &keylen,
&txn_obj, db_txn_ce) == FAILURE)
{
return;
}
if(txn_obj) {
getDbTxnfromThis(txn);
flags = 0;
}
memset(&key, 0, sizeof(DBT));
key.data = keyname;
key.size = keylen;
RETURN_LONG(db->del(db, txn, &key, flags));
}
/* }}} */
因为我没有传递txn对象,因此txn_obj判断为false,出错原因就很简单了:
flags没初始化。
看起来低级错误谁都会犯。
修正后测试正常。
相关文档:
看yii框架源码的时候,发现了
ReflectionClass这个方法,才发现原来是php5的新东西,于是稍微研究了下。php的反射api一共有:
class
Reflection
{ }
interface Reflector
{ }
class
ReflectionException
extends
Exception
{ }
class
Re ......
In the directory where you plan to install Elgg, do the following:
Create the file .htaccess and add these two lines
RewriteEngine on
RewriteRule ^testing.php$ modrewrite.php
This tells the webserver to load modrewrite.php when testing.php is
requested.
In order to get this test to work on ......
环境软件版本介绍:
APACHE 2.0.59
PHP5.2.3
MYSQL5.0.45
GD-2.0.35
Zend Optimizer v3.3.0
  ......
<?php
set_time_limit(0);
$url='http://item.taobao.com/auction/item_detail.htm?xid=0db2&item_num_id=4512430274&cm_cat=50000671&pm2=1';
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CU ......