如何从 500 内部错误中删除时间和内存 - Zend

How to remove time and memory from 500 internal error - Zend

实际上500内部错误是"Time-Memory-Function-Location"的组合。

现在我想从 500 内部错误中删除时间和内存。

实际输出:

#TimeMemoryFunctionLocation
10.0002365832{main}(  ).../http.php:0
20.05691577072Zend\Mvc\Application->run(  ).../http.php:48
30.06211677272Zend\EventManager\EventManager->triggerEventUntil(  ).../Application.php:332
40.06211677272Zend\EventManager\EventManager->triggerListeners(  ).../EventManager.php:179
50.06221677912Zend\Mvc\DispatchListener->onDispatch(  ).../EventManager.php:322
60.06261682144WebService\Controller\User\ManageAccountController->dispatch(  ).../DispatchListener.php:138
70.06261682144WebService\Controller\User\ManageAccountController->dispatch(  ).../AbstractRestfulController.php:313
80.06261682464Zend\EventManager\EventManager->triggerEventUntil(  ).../AbstractController.php:106
90.06261682464Zend\EventManager\EventManager->triggerListeners(  ).../EventManager.php:179
100.06281686864WebService\Controller\User\ManageAccountController->onDispatch(  ).../EventManager.php:322
110.07321939200WebService\Controller\User\ManageAccountController->onDispatch(  ).../AbstractController.php:129
120.07321939232WebService\Controller\User\ManageAccountController->processPostData(  ).../AbstractRestfulController.php:429
130.07341945960WebService\Controller\User\ManageAccountController->create(  ).../AbstractController.php:234
140.08922331024Model\Model\UserModel->updateUser(  ).../ManageAccountController.php:50
150.08932331464Model\Mapper\UserMapper->updateUserData(  ).../UserModel.php:560
160.08932332744Application\Database\Connection->execute(  ).../UserMapper.php:475
170.08942332840Zend\Db\Adapter\Adapter->query(  ).../Connection.php:77
180.08942244472Zend\Db\Adapter\Driver\Mysqli\Statement->prepare(  ).../Adapter.php:193

预期输出:

{main}(  ).../http.php:0
Zend\Mvc\Application->run(  ).../http.php:48
Zend\EventManager\EventManager->triggerEventUntil(  ).../Application.php:332
Zend\EventManager\EventManager->triggerListeners(  ).../EventManager.php:179
Zend\Mvc\DispatchListener->onDispatch(  ).../EventManager.php:322
WebService\Controller\User\ManageAccountController->dispatch(  ).../DispatchListener.php:138
WebService\Controller\User\ManageAccountController->dispatch(  ).../AbstractRestfulController.php:313
Zend\EventManager\EventManager->triggerEventUntil(  ).../AbstractController.php:106
Zend\EventManager\EventManager->triggerListeners(  ).../EventManager.php:179
WebService\Controller\User\ManageAccountController->onDispatch(  ).../EventManager.php:322
WebService\Controller\User\ManageAccountController->onDispatch(  ).../AbstractController.php:129
WebService\Controller\User\ManageAccountController->processPostData(  ).../AbstractRestfulController.php:429
WebService\Controller\User\ManageAccountController->create(  ).../AbstractController.php:234
Model\Model\UserModel->updateUser(  ).../ManageAccountController.php:50
Model\Mapper\UserMapper->updateUserData(  ).../UserModel.php:560
Application\Database\Connection->execute(  ).../UserMapper.php:475
Zend\Db\Adapter\Adapter->query(  ).../Connection.php:77
Zend\Db\Adapter\Driver\Mysqli\Statement->prepare(  ).../Adapter.php:193

我试过这个正则表达式。但是我没有得到解决方案

/[\d\.]*([a-zA-Z\.\/\\->\(\) {}]*:\d*)/g 

请帮我解决问题。

您可以匹配 1 个或多个数字,然后是一个点,然后再匹配 1 个或多个数字,并断言右边的内容是模式 {...} 或 1+ 个单词字符后跟 \ 使其更具体一些。

^\d+\.\d+(?={[^{}]*}|\w+\)

在替换中使用空字符串。

说明

  • ^ 字符串开头
  • \d+\.\d+匹配1+个数字,一个点和1+个数字
  • (?=正向前瞻,断言右边的是
    • {[^{}]*} 匹配 {} 之间不匹配 {}
    • |
    • \w+\ 匹配 1+ 个单词字符后跟 \
  • ) 关闭前瞻

Regex demo | Php demo

如果您还想删除 #TimeMemoryFunctionLocation,您可以使用 \G 锚点

(?:#TimeMemoryFunctionLocation\R|\G)\d+\.\d+((?:{[^{}]*}|\w+\).*\R*)
  • (?:非捕获组
    • #TimeMemoryFunctionLocation\R 匹配 #TimeMemoryFunctionLocation 和一个 unicode 换行符序列
    • |
    • \G 在上一场比赛结束时断言位置,在这种情况下将在字符串的开头
  • ) 关闭群组
  • \d+\.\d+匹配1+个数字,一个点和1+个数字
  • ( 捕获 组 1
    • (?:{[^{}]*}|\w+\)
    • .*\R* 匹配该行的其余部分和 0+ unicode 换行序列
  • ) 关闭组 1

Regex demo | Php demo

在替换中使用捕获组 1

例如

$re = '/(?:#TimeMemoryFunctionLocation\R|\G)\d+\.\d+((?:{[^{}]*}|\w+\\).*\R*)/';
$str = "...";
$result = preg_replace($re, '', $str);

例如,使用第一个模式:

$re = '/^\d+\.\d+(?={[^{}]*}|\w+\\)/m';
$str = '#TimeMemoryFunctionLocation
10.0002365832{main}(  ).../http.php:0
20.05691577072Zend\Mvc\Application->run(  ).../http.php:48
30.06211677272Zend\EventManager\EventManager->triggerEventUntil(  ).../Application.php:332
40.06211677272Zend\EventManager\EventManager->triggerListeners(  ).../EventManager.php:179
50.06221677912Zend\Mvc\DispatchListener->onDispatch(  ).../EventManager.php:322
60.06261682144WebService\Controller\User\ManageAccountController->dispatch(  ).../DispatchListener.php:138
70.06261682144WebService\Controller\User\ManageAccountController->dispatch(  ).../AbstractRestfulController.php:313
80.06261682464Zend\EventManager\EventManager->triggerEventUntil(  ).../AbstractController.php:106
90.06261682464Zend\EventManager\EventManager->triggerListeners(  ).../EventManager.php:179
100.06281686864WebService\Controller\User\ManageAccountController->onDispatch(  ).../EventManager.php:322
110.07321939200WebService\Controller\User\ManageAccountController->onDispatch(  ).../AbstractController.php:129
120.07321939232WebService\Controller\User\ManageAccountController->processPostData(  ).../AbstractRestfulController.php:429
130.07341945960WebService\Controller\User\ManageAccountController->create(  ).../AbstractController.php:234
140.08922331024Model\Model\UserModel->updateUser(  ).../ManageAccountController.php:50
150.08932331464Model\Mapper\UserMapper->updateUserData(  ).../UserModel.php:560
160.08932332744Application\Database\Connection->execute(  ).../UserMapper.php:475
170.08942332840Zend\Db\Adapter\Adapter->query(  ).../Connection.php:77
180.08942244472Zend\Db\Adapter\Driver\Mysqli\Statement->prepare(  ).../Adapter.php:193';

$result = preg_replace($re, '', $str);

echo $result;

输出

#TimeMemoryFunctionLocation
{main}(  ).../http.php:0
Zend\Mvc\Application->run(  ).../http.php:48
Zend\EventManager\EventManager->triggerEventUntil(  ).../Application.php:332
Zend\EventManager\EventManager->triggerListeners(  ).../EventManager.php:179
Zend\Mvc\DispatchListener->onDispatch(  ).../EventManager.php:322
WebService\Controller\User\ManageAccountController->dispatch(  ).../DispatchListener.php:138
WebService\Controller\User\ManageAccountController->dispatch(  ).../AbstractRestfulController.php:313
Zend\EventManager\EventManager->triggerEventUntil(  ).../AbstractController.php:106
Zend\EventManager\EventManager->triggerListeners(  ).../EventManager.php:179
WebService\Controller\User\ManageAccountController->onDispatch(  ).../EventManager.php:322
WebService\Controller\User\ManageAccountController->onDispatch(  ).../AbstractController.php:129
WebService\Controller\User\ManageAccountController->processPostData(  ).../AbstractRestfulController.php:429
WebService\Controller\User\ManageAccountController->create(  ).../AbstractController.php:234
Model\Model\UserModel->updateUser(  ).../ManageAccountController.php:50
Model\Mapper\UserMapper->updateUserData(  ).../UserModel.php:560
Application\Database\Connection->execute(  ).../UserMapper.php:475
Zend\Db\Adapter\Adapter->query(  ).../Connection.php:77
Zend\Db\Adapter\Driver\Mysqli\Statement->prepare(  ).../Adapter.php:193