New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MySQLi abstract layer dont works with hhvm, PHP without hhvm its works #4505
Comments
Line Also, proper formatting would be nice 😜 |
This code makes me cry. Every time you write a class misusing Anyway, you say HHVM crashes, can you provide a stack trace? Install hhvm-dbg or hhvm-nightly-dbg and make it crash once again. The stack trace should then be in /tmp. |
I've update de orginal issue, and the error is at line 49. with hhvm-dbg, the stack trace display this: Host: maquina ThreadType: Web Request 0 bt_handler at /tmp/tmp.JlCliioODY/hphp/runtime/base/crash-reporter.cpp:71 PHP Stacktrace: |
When I execute directly in a terminal in terminal
Display this: |
Part 1 The function definitions of bind-param() and bind-result() in http://php.net/manual/en/mysqli-stmt.bind-param.php and http://php.net/manual/en/mysqli-stmt.bind-result.php expect variable references (mixed &$var1). You are passing number 0, which is not a reference. So you can try:
Both hhvm 3.3 and 3.4 work. Part 2 If I only correct $data but not $fields, for example However, hhvm shouldn't crash. Adding some checks about if the variable has the correct type in bytecode.cpp to stop executing the function from reflection or in ext_mysqli.cpp (line 129) can prevent from toInt64Helper() crashing and corruption. Part 3 If I change the lines My understanding is that bind_param_helper() in ext_mysqli.cpp stores all the arguments in a vector and calls arReturn() at the end. The reference variables are freed in arReturn() due to this commit, so update_result() in mysql_common.cpp can't set the result later ( Part 4: Memory leak Since that commit was about fixing memory leak, I reverted that commit and did a stress test. I found that the memory leaked so fast that somewhere else must be leaking. jemalloc profiling dumps showed MySQLStmt::bind_result() leaked. It turned out that ~MySQLStmt() and ~MySQLStmtVariables() were never called. The buffer will also leak if the result has strings. Every time hhvm runs your scripts above, it will be gradually leaking memory (about 1gb/5000 requests in my testing). |
…structs. Part 4 of facebook#4505.
@wjywbs: nice debugging, thanks! |
This mysqli abstract layer work very well with php-fpm and nignx. But when Im trying to implement it with HHVM + nginx there isn't way to got working correctly.
I think the problem is around the Reflection class to pass the arguments to be bind (bind params, bind results) as arrays.
connect_errno) { print("Página no disponible. Intente de nuevo más tarde."); exit(); } } protected static function prepare() { self::$stmt = self::$conn->prepare(self::$sql); self::$reflection = new ReflectionClass('mysqli_stmt'); } protected static function setParams() { $method = self::$reflection->getMethod('bind_param'); $method->invokeArgs(self::$stmt, self::$data); } protected static function getData($fields) { self::$results = array(); $method = self::$reflection->getMethod('bind_result'); $method->invokeArgs(self::$stmt, $fields); while(self::$stmt->fetch()) { self::$results[] = unserialize(serialize($fields)); } } protected static function close() { self::$stmt->close(); self::$conn->close(); } public static function execute($sql, $data, $fields=False) { self::$sql = strtolower($sql); self::$data = $data; self::open(); self::$conn->set_charset("utf8"); self::prepare(); self::setParams(); self::$stmt->execute(); if($fields) { self::getData($fields); return self::$results; } else { if(strpos(self::$sql, strtolower('INSERT')) === 0) { return self::$conn->insert_id; } } self::close(); } ``` } ?>example :
$sql = "SELECT user_id, name FROM user WHERE user_id > ?";
$data = array("i",0);
$fields = array('ID'=>'', 'NAME=>'');
$fields = DBModel::execute($sql, $data, $fields);
var_dump($fields);
The error log display:
\nWarning: Argument 1 not passed as reference
\nNotice: Array to string conversion in /var/www/core/DBModel.php on line 49
\nNotice: Array to string conversion in /var/www/core/DBModel.php on line 49
Core dumped: Aborted
Stack trace in /tmp/stacktrace.11929.log
And then HHVM crashes!
I'm not the author of this layer. more infor about http://pastebin.com/SHwDkQzL
The text was updated successfully, but these errors were encountered: