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