【发布时间】:2018-07-27 07:30:25
【问题描述】:
我非常喜欢在 laravel 中使用 xdebug(尤其是 vim)。然而最近发生了一些奇怪的事情(注意:当我使用这个命令在单元测试中运行它时,我的 xdebug 工作得很好:
php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 ./vendor/bin/phpunit
- 我首先在控制器方法中放置断点,例如
- 我在浏览器上运行该命令会触发将调用该控制器方法的 http 调用 断点出现在这里:(project/path/serve.php)
<?php <------- breakpoint appears here
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
如果我输入命令“获取所有上下文”,我会得到:
$uri = /* uninitialized */'';
单步执行转到 if ($uri 行,在这种情况下,uri 会正确显示在 contxt 中
当我跳过该文件的末尾时,它会立即跳到这里:
/**
* Handle the PHP shutdown event.
*
* @return void
*/
public function handleShutdown()
{
if (! is_null($error = error_get_last()) && $this->isFatal($error['type'])) {
在
Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()
然后它立即转到raven服务提供者:
/**
* Register the service provider.
*/
public function register()
{
..
// Register the fatal error handler.
register_shutdown_function(function () {
if (isset($this->app['Raven_Client'])) { <---- comes here
(new Raven_ErrorHandler($this->app['Raven_Client']))->registerShutdownFunction();
}
});
在
Jenssegers\Raven\RavenServiceProvider->Jenssegers\Raven\{closure}()
然后在这里@Raven_Client->onShutdown() /path/to/project/vendor/sentry/sentry/lib/Raven/Client.php:1388
public function onShutdown()
{
if (!defined('RAVEN_CLIENT_END_REACHED')) { <--
define('RAVEN_CLIENT_END_REACHED', true);
}
$this->sendUnsentErrors();
if ($this->curl_method == 'async') {
$this->_curl_handler->join();
}
}
那么这里@Raven_ErrorHandler->handleFatalError() /path/to/project/vendor/sentry/sentry/lib/Raven/ErrorHandler.php:126
public function handleFatalError()
{
unset($this->reservedMemory); <---
if (null === $error = error_get_last()) {
return;
}
if ($this->shouldCaptureFatalError($error['type'])) {
$e = new ErrorException(
@$error['message'], 0, @$error['type'],
@$error['file'], @$error['line']
);
$this->handleException($e, true);
}
那么这里@Monolog\Handler\RotatingFileHandler->__destruct() /path/to/project/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php:169
public function __destruct()
{
try {
$this->close();
} catch (\Exception $e) {
// do nothing
} catch (\Throwable $e) {
// do nothing
}
}
如何阻止这种情况发生?
更新
我通过这样做从我的环境中删除了 raven 服务提供者:
类 AppServiceProvider 扩展了 ServiceProvider {
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$env = config('app.env');
if (!$env === 'local' || !$env === 'testing') {
$this->app->register(\Jenssegers\Raven\RavenServiceProvider::class);
$this->app->alias('Raven', Jenssegers\Raven\Facades\Raven::class);
}
但是现在当我调试时,它仍然在这里:
/**
* Handle the PHP shutdown event.
*
* @return void
*/
public function handleShutdown()
{
if (! is_null($error = error_get_last()) && $this->isFatal($error['type'])) {
在
Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()
但它跳过了乌鸦的东西..所以这真的是我的问题。发生了一个错误,但我想在遇到该错误之前进行调试..
更新 2
- 我注意到中间件中的断点工作正常,但随后它继续跳过我的控制器
- 如果我从邮递员发出请求(我切换到登录 api 进行烟熏),它工作得很好,这就是我的邮递员命令的样子(转换为 curl):
>
curl --request POST \
--url 'http://127.0.0.1:8000/api/users/login' \
--header 'Accept: application/x.toters.v1+json' \
--header 'Content-Type: application/json' \
--header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
--form 'email={{client_user_name}}' \
--form 'password={{general_password}}'
另一方面,这是来自浏览器的请求不起作用:
curl 'http://127.0.0.1:8000/api/users/login'
-X OPTIONS
-H 'Access-Control-Request-Method: POST'
-H 'Origin: http://localhost:3000'
-H 'Accept-Encoding: gzip, deflate, br'
-H 'Accept-Language: en-US,en;q=0.9'
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36'
-H 'Accept: */*'
-H 'Connection: keep-alive'
-H 'Access-Control-Request-Headers: content-type' --compressed
【问题讨论】:
-
如果调试器跳转到任何异常处理程序,是否捕获到任何异常?
-
我认为它甚至还没有进入该部分..这整个事情发生在完全到达异常部分之前
-
您是否在用于开发的同一系统上运行网络服务器?在 debian 系统上使用 Apache 并在
vendor文件夹不包含所有包的 Windows 系统上进行本地开发时,我遇到了类似的问题 -
都在同一个环境中
标签: php laravel xdebug sentry raven