Start PHP Debug step by step on Form Submit - php

I would like to know if there may be a way to run a debug step by step when click on input button type "submit". At this time I run the debug step by step with Xdebug but the problem is that I can't finding a way to start a debugging step by step when I send a form. Can you give me some advice please?
Unfortunately, from the answers I didn't understand what I have to do. I share some configuration information I have in my Virtual Machine.
I hope it can help :
I set /etc/php/8.0/cli/conf.d/20-xdebug.ini in this mode:
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host = localhost
xdebug.client_port = 9002
Here launch.json in VSCode (works only "Launch currently open script" but "Listen for Xdebug" and "Launch Built-in web server" don't work and i dont'know why):
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9002
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=trigger",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9002,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}

You can use a hidden form variable with the name XDEBUG_SESSION and as value pretty much anything.
For this to work, you need to have:
Xdebug 3
Set xdebug.start_with_request=trigger
And all the standard configuration settings for enabling Step Debugging.

Related

Setup Xdebug configuration for PHP scripts called in cron by docker-entrypoint.sh in VSCode

Currently using VSCode on MacOS, Xdebug is working well for my PHP web application ran with docker.
But I also have some PHP scripts that are called by the docker-entrypoint.sh as crons and I'd like to be able to debug them as well. I can't configure it properly, nothing happens when I set breakpoints while the crons are running.
Here is my launch.json configuration at the moment (all the codesource - web, scripts...- is under myapp/app) :
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9001,
"log": true,
"pathMappings": {
"/opt/myapp/app": "/Users/me/src/myapp/app"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9002,
"log": true
}
]
}
In my docker-compose.yml, I also have PHP_XDEBUG_ENABLED=true for the web container and the cron container of course.
Any ideas / configuration examples to get the debug working for the PHP crons ?

Xdebug is successfully installed on Windows but not working

I downloaded the dll file by copy-pasting the phpinfo() output to Xdebug site, so I think I got the right file.
I edited my php.ini file and restarted Apache web server (I'm using XAMPP).
I set breakpoints, hit "Add Configuration" and Run the debug in Visual Studio Code.
Unfortunately, the breakpoint did not worked.
I have gone through many topics, tutorials but it still not works.
This is how my php.ini file looks like:
[XDebug]
zend_extension = "D:\xampp\php\ext\php_xdebug-3.0.4-8.0-vs16-x86_64.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
This is my config file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
This is the image I took using the xdebug_info();
Your help save my day.
Your screenshot shows that you don't have the Step Debugger enabled (it says "Disabled").
Your config says:
zend_extension = "D:\xampp\php\ext\php_xdebug-3.0.4-8.0-vs16-x86_64.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
Xdebug 3 does no longer use xdebug.remote_enable or xdebug.remote_autostart. As per the Upgrade Guide these have been renamed to:
xdebug.mode=debug
xdebug.start_with_request=yes
The "Docs" column in your screenshot also links to the documentation for that specific feature.
My solution after trying the instruction with windows and xampp:
Just download the xdebug extension again and do the instructions!

Xdebug is working but not stopping at breakpoints in VSCode

I'm using XAMPP and have installed Xdebug from Xdebug Wizard page, but renamed php_xdebug-3.0.2-7.2-vc15-x86_64.dll to php_xdebug.dll
My php.ini:
[XDebug]
xdebug.remote_enable=1
xdebug.remote_autostart=1
zend_extension="C:\xampp\php\ext\php_xdebug.dll"
my launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
I have this extension installed:
When run I get this output in the console:
When I set the listen Xdebug:
And open the program it goes trough the breakpoint:

Unable to get Xdebug to work on VSCode with browser extension

I'm trying to setup Xdebug on my VSCode, to do so I installed the PHP Debug extension and set the launch.json as so :
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"stopOnEntry": true,
"pathMappings": {
"/Users/me/Desktop/www/my_current_project": "${workspaceFolder}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
For the extension on chrome I use Xdebug helper, and I'm not sure if it's supposed to work without cookie or not in the case of VSCode (because PHPStorm needs one), but I've set the cookie value to "VSCODE" as I found somewhere on the internet...and the extension is enabled (green).
Then, I clicked on "Listen for Xdebug" on VSCode, and set some breakpoints on my script, but VSCode does not respond to me calling the script from the browser.
I have not found so far any solution that worked for me, I guess there's an issue in the launch.json file maybe..

How to PHP debug multiple websites in VS Code

Expected behavior:
I have multiple PHP projects on different servers, usually I debug them with PhpStorm which allows me to configure path mappings for remote debugging per server. Thus I can have the same remote paths e.g. /var/www/html for different servers.
Problem description:
So far I have been unable to configure multiple servers with the same remote paths using VSCode.
I use the most used php-debug plugin for VSCode and have not found any information regarding this issue on the projects GitHub page or anywhere else.
Currently I do not think configuring multiple remote servers using VSCode is possible at this time but in case someone knows a way I would appreciate it.
Current configuration:
With the following configuration I can only debug one project at once and have to change the paths manually when I want to debug another project on another server with the same remote paths.
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "/local/project/path",
"/var/www/html/src/shared:": "/local/shared/src/path",
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Step 1
To debug multiple websites with VSCode first add multiple configurations to the vscode-php-debug extensions config (Run->Open Configurations) with different names.
{
"version": "0.2.0",
"configurations": [
{
"name": "website 1",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "/local/project/path1",
}
},
{
"name": "website 2",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "/local/project/path2",
}
},
{
"name": "website 3",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "/local/project/path3",
}
},
]
}
Step 2
You then have to select the appropriate configuration before debugging your code by clicking on the current configuration in the bottom left hand corner or writing debug in the top bar (ctrl+t and remove the hash) (which will make that configuration the default for the current session and immediately launch debugging).

Categories