In my Symfony application I am using IntelliJ Ultimate + Xdebug + Vagrant VM with an remote debug setting in IntelliJ. In the Vagrant box there is PHP 7.2 and Xdebug 2.6 installed
When I start a debug session via browser, everything works fine. I can step through all my code perfectly.
But when I start a remote debug session inside VM via
XDEBUG_CONFIG="remote_host=10.10.0.1" PHP_IDE_CONFIG="serverName=abc" bin/console <command>
The Xdebug works also but it misses the lines in my local source code. In IntelliJ I am always one line ahead as the debugger seems to be. I can see it when for example a new variable is created in my local source code. Just one step later the debugger info shows me, that it was created. Another example: if I step over a code line I am suddenly on an empty line.
If I set the breakpoint as follows
$a = "abc";
o echo $a;
echo "test";
The debugger stops, but $a isn't initialized yet (as seen in the variables section). If I now step over
$a = "abc";
echo $a;
o
echo "test";
$a is initialized now, but not outputted by the echo command and the debugger is on an empty line.
Next step over leads to
$a = "abc";
echo $a;
echo "test";
o
and so on ...
The only tip I can find is: Check the path mapping. I am sure, the path mapping is really okay because it actually finds all the files I want to debug but it stops on the wrong line.
I also compared the files in my vagrant source code and my local source code. They are exactly the same. I think they cannot be out of sync cause the source code is shared with the VM via shared folder.
I also looked into Xdebug log file which tells me line numbers. These line numbers are exactly the same as in my local code, so nothing unusual here.
Strange is: The bin/console php file works correct, but classes instantiated from here does not.
Does somebody has a clue, what I can check else? Is there a known bug or anything else? Its no option to debug all my command line executed code via die() and print() commands ...
Related
I'm trying to add debugging to an old project that uses exec() to start a new session asynchronously from within another PHP script:
exec("php /var/www/html/validata/index.php",$result)
The normal PHP script is fully debugable with Xdebug but the script started with the exec command isn't because it can't map from file:///var/www/html/index.php to a local file location since it's started within CLI shell. The session started this way does trigger the debugger but can't find the file locally:
Cannot find file '/var/www/html/validata/index.php' locally.
To fix it set server name by environment variable PHP_IDE_CONFIG and restart debug session.
I've followed the instructions to add the PHP_IDE_CONFIG to the env. I've also added this to the server with 127.0.0.1 replaced with the desktop PC IP address (server is running in a docker container):
export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"
Any pointers are greatly appreciated!
UPDATE
Solution:
Use the cli interpreter set to the docker container (in settings > Languages & Frameworks > PHP > CLI interpreter, add new, select docker and point it to the php binary) so that a debug session can be started with a new debugging configuration. I've copied the arguments from the exec command into the new configuration and it can now fully debug the script. I have to prepare a database table to make it fully testable but this is a working solution for me.
Thanks for all the replies!
You can solve the issue about the wrong php.ini file being loaded by specifying it in the command line:
exec("php -c " . escapeshellarg(php_ini_loaded_file()) .
" /var/www/html/validata/index.php",$result);
Though I doubt that would make much of a difference as far as xdebug is concerned.
I think a better solution would be to just require the file, which would cause xdebug to not become lost when you fork a new process.
require_once "/var/www/html/validata/index.php";
I've made a mistake how to refer to the server in PHP_IDE_CONFIG:
export PHP_IDE_CONFIG="serverName=SomeName"
should be run in the container where php runs, and SomeName should exactly match what is in PHPStorm/IntelliJ Settings > Languages & Frameworks > php > Servers > Name (not host). It's not a fqdn, just whatever is in the name field.
I installed the phptidy plugin for Sublime Text 2 and tried to use it to clean up some ugly code like
$tdt="<td class=\"tit2\" ";
$linka='<a href="products.php?action=history5&item=';
while ($row=mysql_fetch_array($r))
{ extract($row);
But after running Php Tidy, a console flashed and it seems to have edited the entire file, but nothing actually changed. Does anyone know if the plugin below still works?
https://github.com/welovewordpress/SublimePhpTidy
I ran into the same problem. Console would open and close too fast to read what was going on.
Step 1: I opened up the Sublime Console (CTRL + ` on Windows)
Step 2: Reading the output gave me the hint. PhpTidy relies on php.exe being installed on your machine (duh)
This last step might seem obvious, but I was networked into another computer where the code lived and coding it over the wire. As such, when I ran phpTidy on my local machine, it failed due to the lack of php itself.
At first you must add the <?php ?> to beginning and end of your PHP file.
If you based-on Win, see the output of PHPTidy Processes on the 'Ctrl+`' Console.
There is a tip:
PhpTidy: calling php.exe -v returned: 0.
If it returns 1, maybe 'php.exe' wasn't found, add the path of your ‘php.exe’ to ENV.
Everything works fine with Firefox, but I can't start chrome. I'm on linux, using php webdriver bindings.
require_once "/usr/local/src/selenium/php-webdriver-bindings-0.9.0/phpwebdriver/WebDriver.php";
putenv("PATH=".getenv("PATH").':'.'/usr/local/src/selenium/chrome_webdriver/'); //Prepare for chrome
$webdriver = new WebDriver("localhost", "4444");
//$webdriver->connect("chrome");
$webdriver->connect("chrome","",array(
'webdriver.chrome.driver'=>'/usr/local/src/selenium/chrome_webdriver/chromedriver',
));
The error message I get is "The path to the chromedriver executable must be set by the webdriver.chrome.driver system property". As you can see, I've tried setting that in the desiredCapabilities array, but that must be the wrong place. I can see in the selenium logs that my setting is getting through as this log line shows:
INFO - Executing: [new session: {javascriptEnabled=true, webdriver.chrome.driver=/usr/local/src/selenium/chrom..., browserName=chrome, nativeEvents=false, version=}] at URL: /session)
I start selenium with java -jar selenium-server-standalone-2.21.0.jar
I'm using Chromium v.18.
I created a shortcut /usr/bin/google-chrome that points to /usr/bin/chromium-browser
I can start chromedriver manually with no problems. It says:
port=9515
version=20.0.1133.0
Having that running, or not, does not make any difference to the error message selenium gives me.
UPDATE: Related question: selenium 2 chrome driver (answer there is for java, not php)
You can try passing the webdriver.chrome.driver property from commandline while starting the selenium server. Like this:
java -Dwebdriver.chrome.driver = pathtochromedriver -jar selenium-server.jar
I am not sure about the reason why the other one is not working. You need to check whether its really setting the system property from code..
Without any blanks it worked for me on WinXP32:
java -Dwebdriver.chrome.driver=C:\chromedriver.exe -jar selenium-server.jar
I have netbeans setup with xdebug so it can debug php. However, this only works if I create a php project. It will not work if I try opening a stand alone php file. So my question is, is it possible to debug a stand alone php file which is not part of a netbeans php project?
If that is not possible, how do I debug stand alone php files with netbeans?
No, There is none that I am aware of. As Myrddin mentioned the debugger needs some configurations that is a part of netbeans project.
but the best way you can debug a single file is to copy it on a project folder, and click the debug project, once the debug session is set then you can browse the PHP File that you want to debug and it will actually go through xdebug.
Good Luck!
Each project can have it's own configuration (you can have 1 project that has PHP5.4 interpreter, one the is PHP5.6, one that is a command line and another that is a web project), but if you configure a general PHP 5 Interpreter:
If you work on a windows machine you can use this code (filename is php.cmd)
set XDEBUG_CONFIG="idekey=netbeans-xdebug"
#php.exe %*
If you want to be able to debug, your interpreter should have the XDEBUG_CONFIG system variable and make sure it's connected to netbeans. You should set this to the same value in your Debbugging section of the PHP's config:
Next thing - if you right click inside the editor you will have the Debug File option, and a prompt window will pop:
You don't really need anything here. Just hit the "OK" button.
As you can see, this final result is debug session of the t1.php file within c:\TEMP\ (which is not a working project):
Short answer: CTRL + SHIFT + F5
You can find the answer here:
https://blogs.oracle.com/netbeansphp/entry/run_file_without_project
I'm not entirely sure, but I think it is not possible, because you need some configuration to get the debugging working, and this configuration is part of a project.
You can always use print_r and var_dump to debug a single file. But that is probably not the answer you're looking for.
xdebug is very heavy and old tool you can use Kint php debuger here.
its free, so you can download Here
it's pretty replacement for var_dump(), print_r() and debug_backtrace().
you need to add kint.class.php file using include or require function.
require '/kint/Kint.class.php';
that's it.
and you can use like
########## DUMP VARIABLE ###########################
Kint::dump($GLOBALS, $_SERVER); // pass any number of parameters
// or simply use d() as a shorthand:
d($_SERVER);
########## DEBUG BACKTRACE #########################
Kint::trace();
more help is available on https://github.com/raveren/kint/
Good Luck :)
I am getting numerous errors exactly like this one:
Zend_Session_Exception: Session must be started before any output has been sent to the browser; output started in /usr/local/zend/share/pear/PHPUnit/Util/Printer.php/173
When running my application's test suite. This is with PHPUnit 3.5.10 and PHP 5.3.5.
There is no mysterious, unexpected whitespace output that is causing this. I've determined that the "output being sent to the browser" is the actual output from the PHPUnit tests being executed. If I open up PHPUnit/Util/Printer.php and wrap the print $buffer line with if (strpos($buffer, 'PHPUnit 3.5.10 by Sebastian Bergmann') === false) (effectively stopping the first line of output from PHPUnit), then my first test succeeds (until the test case outputs a dot indicating that the test succeeded, then the next test fails because the dot was output).
Another developer on my team is able to run the full test suite successfully, so I know it's not a problem with the application code. It must be some configuration setting or problem with my local environment.
I've already checked php.ini to verify that output_buffering is turned on and implicit_flush is turned off, and they are.
I've also tried adding Zend_Session::$_unitTestEnabled = true; to my test bootstrap, but that didn't help (and shouldn't be necessary anyway because it works on another developer's machine and on our CI server without it).
Any suggestions besides ignoring the errors? I've never seen anything like this and am truly at a loss.
Thanks!
UPDATE:
To attempt to further isolate the problem, I took ZF and my application out of the equation by executing the following test script:
<?php
class SessionTest extends PHPUnit_Framework_TestCase
{
public function testSession()
{
session_start();
$this->assertTrue(true);
}
}
The test fails:
1) SessionTest::testSession
session_start(): Cannot send session cookie - headers already sent by (output started at /home/mmsa/test.php:1)
However, the exact same test works on a friend's machine. Same version of PHP and PHPUnit.
Run phpunit with the -stderr flag, (newer versions may use --stderr instead) e.g.
phpunit -stderr mytest.php
# or
phpunit --stderr mytest.php
This directs phpunit's output to stderr, preventing it from interrupting HTTP header generation.
It's possible that the test works on your friend's machine because he has output buffering enabled (although I'm not sure if that's relevant in a CLI context).
I think better way is use
Zend_Session::$_unitTestEnabled = true;
Using this in my test bootstrap prevents from this error.
If the php binary being used by PHPUnit on your system is the CGI instead of the CLI version, then session_start is really going to try to set cookies and you'll get that error.
You can check to make sure what SAPI you're using by calling php_sapi_name.
I had the same problem with another project, and I found that the issue was PHPUnit causing output to start too soon, because it outputs it's welcome message before running your test.
Added the following two lines to bootstrap.php:
ini_set('session.use_cookies', 0);
ini_set('session.cache_limiter', '');
This should prevent the headers from being sent before your test suite runs.
Like Makor said, you just need to add this in your bootstrap.php
Zend_Session::$_unitTestEnabled = true;
In my case, I put something like in my bootstrap.php file
if(APPLICATION_ENV == 'testing' && php_sapi_name() == 'cli') {
Zend_Session::$_unitTestEnabled = true;
}
So you don't have to change it anymore.