我正在尝试调试通过CLI执行的Laravel工匠命令,后者又调用外部端点(通过Guzzle)。 原始应用程序和外部端点都在本地可用,在PHPStorm中作为两个单独的项目打开。
我可以通过在终端中运行此命令来调试CLI命令:
export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"
(或对于Windows):
set XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"
如PHPStorm docs所示,您可以通过传递调试查询字符串来执行外部脚本:
$debuggingQuerystring = '';
if (isset($_GET['XDEBUG_SESSION_START'])) { // xdebug
$debuggingQuerystring = 'XDEBUG_SESSION_START=' . $_GET['XDEBUG_SESSION_START'];
}
if (isset($_COOKIE['XDEBUG_SESSION'])) { // xdebug (cookie)
$debuggingQuerystring = 'XDEBUG_SESSION_START=PHPSTORM';
}
if (isset($_GET['start_debug'])) { // zend debugger
$debuggingQuerystring = 'start_debug=' . $_GET['start_debug'];
}
$personJson = file_get_contents('http://127.0.0.1:778/backend.php?' . $debuggingQuerystring);
当前通过CLI执行时,$ debugQueryString为空的问题。我们传递了什么以及如何在第二个项目上调试外部URL?
$client = new Guzzle\Http\Client($this->webhook_url);
$response = $client->post('', [], $this->params)->send();
$code = $response->getStatusCode();
答案 0 :(得分:0)
这比我想象的容易。
$debuggingQuerystring = '';
if (isset($_GET['XDEBUG_SESSION_START'])) { // xdebug
$debuggingQuerystring = 'XDEBUG_SESSION_START=' . $_GET['XDEBUG_SESSION_START'];
}
if (isset($_COOKIE['XDEBUG_SESSION'])) { // xdebug (cookie)
$debuggingQuerystring = 'XDEBUG_SESSION_START=PHPSTORM';
}
if (isset($_GET['start_debug'])) { // zend debugger
$debuggingQuerystring = 'start_debug=' . $_GET['start_debug'];
}
if(empty($debuggingQuerystring))
{
$debuggingQuerystring = 'XDEBUG_SESSION_START=PHPSTORM';
}
$this->debugString = $debuggingQuerystring;
然后是网址:
$client = new Guzzle\Http\Client($this->webhook_url);
$response = $client->post('?' . $this->debugString, [], $this->final_data)->send();
$code = $response->getStatusCode();