执行存储过程时,PHP Apache崩溃 [英] PHP Apache crashes while executing a STORED PROCEDURE

查看:97
本文介绍了执行存储过程时,PHP Apache崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行以下代码时(我正在调用具有5个IN参数和1个OUT参数的存储过程)

When I execute the following code (I'm calling a stored procedure with 5 IN parameters and 1 OUT parameter)

$conn->query("SET @res = ''");

$mysqli=$conn;
if (!($stmt = $mysqli->prepare("CALL retrieve_matches(5,3, 16, 2, false, @res)"))) {
    echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}

if (!$stmt->execute()) {
    echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}

do {
    if ($res = $stmt->get_result()) { //Apache crash on this call
        printf("---\n");
        var_dump(mysqli_fetch_all($res));
        mysqli_free_result($res);
    } else {
        if ($stmt->errno) {
            echo "Store failed: (" . $stmt->errno . ") " . $stmt->error;
        }
    }
} while ($stmt->more_results() && $stmt->next_result());

apache崩溃并显示错误:

apache is crashing with error:

AH00428:父级:子进程9628退出,状态为255-重新启动.

AH00428: Parent: child process 9628 exited with status 255 -- Restarting.

我尝试过的

  1. 此代码可以正常工作,并且可以正确返回结果:

$conn->query("SET @res = ''");
$res=$conn->query("CALL retrieve_matches(5,3, 16, 2, false, @res)");
var_dump($res->fetch_assoc());

注意:如果我仅更改存储过程输入中的数字,则与上述使Apache崩溃的代码相同,即可正常工作:

NOTE: The same code above that make Apache crashing is working correctly if I just change the number in input of the stored procedure like:

if (!($stmt = $mysqli->prepare("CALL retrieve_matches(5,6, 16, 2, false, @res)"))) {

  1. 在MySQl工作台上尝试过,两个调用都工作正常.
  2. 我在WIN7 Enterprise 64b上使用WAMP 64b,我尝试了WAMP 32b,但是遇到了同样的问题.
  3. 我检查了Windows事件,发现php5ts.dll导致httpd.exe崩溃
  4. 如果您在Google上搜索"httpd.exe php5ts.dll",您会发现很多人都在解决此问题.但是我没有找到WAMP的解决方案...
  5. 尝试过AMPPS,完全一样的问题

PHP错误日志

[10-Jul-2015 15:30:03 UTC] PHP Warning:  PHP Startup: Unable to load dynamic library 'C:/Program Files/wamp/bin/php/php5.5.12/ext/php_ldap.dll' - Impossibile trovare il modulo specificato.

 in Unknown on line 0

[10-Jul-2015 15:30:04 UTC] PHP Warning:  PHP Startup: Unable to load dynamic library 'C:/Program Files/wamp/bin/php/php5.5.12/ext/php_intl.dll' - Impossibile trovare il modulo specificato.

APACHE错误日志:

APACHE error log:

[Tue Jul 14 15:02:13.038276 2015] [mpm_winnt:notice] [pid 7044:tid 404] AH00428: Parent: child process 9448 exited with status 255 -- Restarting.
[Tue Jul 14 15:02:13.324305 2015] [mpm_winnt:notice] [pid 7044:tid 404] AH00455: Apache/2.4.9 (Win32) PHP/5.5.12 configured -- resuming normal operations
[Tue Jul 14 15:02:13.329306 2015] [mpm_winnt:notice] [pid 7044:tid 404] AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:13:13
[Tue Jul 14 15:02:13.329306 2015] [core:notice] [pid 7044:tid 404] AH00094: Command line: 'C:\\Program Files\\wamp\\bin\\apache\\apache2.4.9\\bin\\httpd.exe -d C:/Program Files/wamp/bin/apache/apache2.4.9'
[Tue Jul 14 15:02:13.352308 2015] [mpm_winnt:notice] [pid 7044:tid 404] AH00418: Parent: Created child process 3140
[Tue Jul 14 15:02:14.528388 2015] [mpm_winnt:notice] [pid 3140:tid 332] AH00354: Child: Starting 64 worker threads.

我在这里真的迷路了,我应该在哪里寻找问题?非常感谢您的帮助

I'm really lost here, where should I look for the issue? Thanks very much for your help

编辑

我意识到存储过程"retrieve_matches"正在使用更改后的值的函数调用不同的存储过程.我调试了存储过程"retrieve_standalone",该过程使Apache崩溃.此过程正在执行选择/插入操作,我检查了一下并正确完成了插入操作.但是在"retrieve_standalone"里面,我正在以一种奇怪的方式使用游标:

I realized that the stored procedure "retrieve_matches" is calling different stored procedure in function of the changed value. I debugged the stored procedure "retrieve_standalone" that is the one that make Apache crashing. This procedure is doing select/insert, I checked and the insert are made correctly. BUT inside "retrieve_standalone" I'm using a cursor in a weird way:

declare bNoMoreRows bool default false;
declare tmp_cursor cursor for
    select comp_id from to_match; -- to_match is a temporary table
declare continue handler for not found set bNoMoreRows := true;

如果我不打开光标

open tmp_cursor;

一切正常!!所以我想我现在找到了问题:我该如何解决?

everything is working fine!! So I guess I found the issue, now: how can I solve it?

推荐答案

显然,在PHP专家和MySQLi专家之间有一些不合理之处-即 scaricabarile .

Apparently there's a bit of buck passing - i.e. scaricabarile - between PHP guys and MySQLi guys.

似乎正在发生的事情是MySQLi以一种不正确"的方式做出反应,并向PHP返回了意外的值(我打赌这是一个NULL),该值已适当地转储到了PHP中.此行为已记录,PHPland的判决是:不是[PHP] 漏洞".在他们一边,MySQLi伙计们坚持认为它的PHP无法正确检查返回的结果.无论如何,不当"结果取决于您的查询.

What seems to be happening is that MySQLi reacts in an "improper" way, and return an unexpected value (I'd bet a small sum on it being a NULL) to PHP, which duly coredumps. This behaviour is documented and the verdict from PHPland is: "Not a [PHP] bug". On their side, the MySQLi guys maintain that it's PHP which is not correctly checking the returned result. And that 'improper' results depended on your query anyway.

因此,我大步走出去,并假设您的问题同样是通信困难"的问题,因此问题就变成了:您的查询迫使MySQLi断开/重新连接".为什么?显然(某些)存储过程

So I'm going out on a limb and supposing that yours is the same problem of "communication difficulties", so the problem becomes: "Your query forces MySQLi to drop/reconnect". Why is that so? Apparently (some) stored procedures require mysqli_multi_query in order to behave properly.

mysqli_multi_query mysqli_prepare不兼容 .

因此,我建议尝试不准备查询,而是使用 mysqli_multi_query 运行它.

So I'd suggest trying without preparing the query, and running it with mysqli_multi_query.

$conn->query("SET @res = ''");
$conn->multi_query("CALL retrieve_matches(5,3, 16, 2, false, @res)");

do {
    if ($result = $conn->store_result()) {
        while ($row = $result->fetch_row()) {
            var_dump($row);
        }
        $result->free();
    }
} while ($conn->more_results() && $conn->next_result());

有了此代码,您的测试用例就可以按预期得到我

With this code, your test case gets me, as expected,

array(1) {
  [0] =>
  string(4) "test"
}

这篇关于执行存储过程时,PHP Apache崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆