xdebug.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /* Copyright (C) 2009-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/admin/system/xdebug.php
  19. * \brief Page administration XDebug
  20. */
  21. // Load Dolibarr environment
  22. require '../../main.inc.php';
  23. $langs->load("admin");
  24. if (!$user->admin) {
  25. accessforbidden();
  26. }
  27. /*
  28. * View
  29. */
  30. llxHeader();
  31. print load_fiche_titre("XDebug", '', 'title_setup');
  32. if (!function_exists('xdebug_is_enabled')) {
  33. print "<br>\n";
  34. print 'XDebug seems to be not installed. Function xdebug_is_enabled not found.';
  35. llxFooter();
  36. exit;
  37. }
  38. print '<span class="opacitymedium">';
  39. print $langs->trans("ModuleActivatedMayExposeInformation", $langs->transnoentities("XDebug"));
  40. print '</span>';
  41. print '<br><br>';
  42. if (function_exists('socket_create')) {
  43. $address = ini_get('xdebug.remote_host') ?ini_get('xdebug.remote_host') : '127.0.0.1';
  44. $port = ini_get('xdebug.remote_port') ?ini_get('xdebug.remote_port') : 9000;
  45. print "<strong>Current xdebug setup:</strong><br>\n";
  46. print "* Remote debug setup:<br>\n";
  47. print 'xdebug.remote_enable = '.ini_get('xdebug.remote_enable')."<br>\n";
  48. print 'xdebug.remote_host = '.$address."<br>\n";
  49. print 'xdebug.remote_port = '.$port."<br>\n";
  50. print "* Profiler setup ";
  51. if (function_exists('xdebug_get_profiler_filename')) {
  52. print xdebug_get_profiler_filename() ? "(currently on into file ".xdebug_get_profiler_filename().")" : "(currently off)";
  53. } else {
  54. print "(currenlty not available)";
  55. }
  56. print ":<br>\n";
  57. print 'xdebug.profiler_enable = '.ini_get('xdebug.profiler_enable')."<br>\n";
  58. print 'xdebug.profiler_enable_trigger = '.ini_get('xdebug.profiler_enable_trigger')."<br>\n";
  59. print 'xdebug.profiler_output_dir = '.ini_get('xdebug.profiler_output_dir')."<br>\n";
  60. print 'xdebug.profiler_output_name = '.ini_get('xdebug.profiler_output_name')."<br>\n";
  61. print 'xdebug.profiler_append = '.ini_get('xdebug.profiler_append')."<br>\n";
  62. print "<br>\n";
  63. print "To run a debug session, add parameter<br>";
  64. print "* XDEBUG_SESSION_START=aname on your URL. To stop, remove cookie XDEBUG_SESSION_START.<br>\n";
  65. print "To run a profiler session (when xdebug.profiler_enable_trigger=1), add parameter<br>\n";
  66. print "* XDEBUG_PROFILE=aname on each URL.<br>";
  67. print "<br>";
  68. print "<strong>Test debugger server (Eclipse for example):</strong><br>\n";
  69. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  70. if (empty($socket)) {
  71. die('Unable to prepare a socket');
  72. }
  73. //socket_bind($sock, $address, $port) or die('Unable to bind on address='.$address.' port='.$port);
  74. //socket_listen($sock);
  75. //$client = socket_accept($sock);
  76. $client = socket_connect($socket, $address, $port);
  77. if ($client) {
  78. print "Connection established: ".$client." - address=".$address." port=".$port."<br>\n";
  79. print "There is a Remote debug server at this address.<br>\n";
  80. print "<br>\n";
  81. print "To be sure this debugger accepts input from your PHP server and xdebug, be sure to have\n";
  82. print "your php.ini file with this :<br>\n";
  83. print '<textarea cols="80" rows="16">'."xdebug.remote_enable=on
  84. xdebug.remote_handle=dbgp
  85. xdebug.remote_host=localhost
  86. xdebug.remote_port=9000
  87. xdebug.profiler_enable=0
  88. xdebug.profiler_enable_trigger=1
  89. xdebug.show_local_vars=off
  90. xdebug.profiler_output_dir=/tmp/xdebug
  91. xdebug.profiler_append=0
  92. ; for xdebug 2.2+
  93. xdebug.trace_enable_trigger=1
  94. xdebug.show_mem_delta=1
  95. xdebug.trace_output_dir=/tmp/trace
  96. xdebug.auto_trace=0
  97. </textarea>\n";
  98. print "<br><br>\n";
  99. print 'Then check in your debug server (Eclipse), you have setup:<br>
  100. XDebug with same port than in php.ini<br>
  101. Allow Remote debug=yes or prompt<br>'."\n";
  102. print "<br>\n";
  103. } else {
  104. print socket_strerror(socket_last_error());
  105. print " - Failed to connect to address=".$address." port=".$port."<br>\n";
  106. print "There is no Remote debug server at this address.\n";
  107. }
  108. socket_close($socket);
  109. } else {
  110. print "Can't test if PHPDebug is OK as PHP socket functions are not enabled.";
  111. }
  112. llxFooter();
  113. $db->close();