Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
Last active July 17, 2019 21:43
Show Gist options
  • Select an option

  • Save mttjohnson/973ba95a0139370c9ba0a1f291bdb0f8 to your computer and use it in GitHub Desktop.

Select an option

Save mttjohnson/973ba95a0139370c9ba0a1f291bdb0f8 to your computer and use it in GitHub Desktop.
xdebug command line enable
# to turn on the remote debugger pass in a config flag to automatically start it
php -d xdebug.remote_autostart=On ...
# just make sure your debugger is referencing the same path as the path of the file you are executing
# for remote debugging, these options should exist in your xdebug.ini file
xdebug.remote_enable = on
xdebug.remote_host = 127.0.0.1
xdebug.idekey = PHPSTORM
xdebug.show_local_vars = on
xdebug.var_display_max_depth = 3
xdebug.max_nesting_level = 250
xdebug.file_link_format = "phpstorm://open?file=%f&line=%l"
xdebug.profiler_enable = 0
xdebug.profiler_output_dir = /tmp
xdebug.profiler_output_name = cachegrind.out.%s.%t
# from there you can rsync down remote code locally for debugging with PHPStorm
rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress \
[email protected]:/var/www/html/current/ /sites/lab-experiments/example.com/
# Establish a tunnel connecting port 9000 on the remote machine
# (which is what xdebug will attempt to connect to) and forward
# any activity from that port to your machine's port 9000
# (where phpstorm will be listening on port 9000)
ssh -N -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-R 9000:localhost:9000 [email protected]
# For diagnosing what xdebug is sending, or if it is even connecting try
# getting something else to listen on port 9000 instead of forwarding to
# phpstorm and just see what's happening:
PHP_CODE="initialized"
set +H # disable history expansion
PHP_CODE=$(cat <<'PHP_CODE'
<?php
$address = '127.0.0.1';
$port = 9000;
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
echo "socket_bind($socket, $address, $port)\n";
socket_bind($socket, $address, $port) or die();
socket_listen($socket);
$client = socket_accept($socket);
echo "connection established: $client",
socket_close($client);
socket_close($socket);
print "\n";
PHP_CODE
)
set -H # re-enable history expansion
echo "${PHP_CODE}" | php
# If that fails to open the port for listening you might check to see if something
# else is already listening on that port:
netstat -ltnp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment