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