fhumanes author
I normally use an IDE environment to debug the code generated by PHPRunner ( MS Visual Studio and Netbeans PHP ). I can only do this on my PC, since on it I configure Apache and the PHP environment to what I need, but I cannot do this on the servers where I upload the applications and where I do not have control of the entire environment . For these cases where I cannot configure my IDE and also, for those users who have not yet taken the step to have an IDE for PHP debugging, we can use a very simple method that I am going to explain to you. The method consists of writing to a file (in this case called “error.log”) that is accessible from any browser. In this way, everything we write in said file can be consulted and it will give us a clue about our problems. To mount the system we have to do: Create a file called “error.log” in the root of our project. For example, if my project has a path of the type “../apache/htdoc/project1”, we will create the file “../apache/htdoc/project1/error.log”
In our PHPRunner project we will insert this code in the “After application initialized” event. This event is executed in all the requests that we make to the application. // To debug PHP code on the server function custom_error($number,$text){ // Function to produce the error file global $debugCode; if ($debugCode == true ) { $ddf = fopen(__DIR__ .'/../error.log','a'); fwrite($ddf,"[".date("r")."] Error $number: $text\r\n"); fclose($ddf); } } $debugCode = true; custom_error(1,"URL ejecutada: ".$_SERVER["REQUEST_URI"]); // To debug If we want it not to write new traces we will set the $debugCode variable to false. We will also delete the “error.log” file on Production systems
Every time we want to write the content of a variable or object, we will use the custom_error() function. For example (see what SQL is being executed. include in the “Before SQL query” event: custom_error(2,"SQL de v_resource: ".$strSQL); // To debug custom_error(2,"WHERE de v_resource: ".$strWhereClause); // To debug
The result of the file is like this: [Thu, 03 Feb 2022 13:03:16 +0100] Error 1: URL ejecutada: /project2/menu.php [Thu, 03 Feb 2022 13:03:18 +0100] Error 1: URL ejecutada: /project2/menu.php [Thu, 03 Feb 2022 13:05:22 +0100] Error 1: URL ejecutada: /project2/v_resource_list.php [Thu, 03 Feb 2022 13:05:22 +0100] Error 2: SQL de v_resource: SELECT `t1`.`task_id`, `t3`.`user_task_id`, `t1`.`projects_project_id`, `t5`.`companies_company_id`, `t5`.`departments_dept_id`, `t5`.`short_name`, `t1`.`parent`, `t1`.`name`, CASE WHEN (t1.percent_complete = 100 )THEN 3 WHEN (t1.end_date < now() and t1.percent_complete < 100 )THEN 2 WHEN (t1.end_date > now() and t1.start_date < now() )THEN 1 ELSE 0 END as `flag`, `t1`.`milestone`, `t1`.`start_date`, `t1`.`duration`, `t1`.`duration_type`, DATEDIFF(t1.end_date,t1.start_date)+1 as `natural_days`, `t1`.`hours_worked`, `t1`.`end_date`, `t1`.`status`, `t1`.`percent_complete`, `t1`.`description`, `t1`.`related_url`, `t1`.`creator`, `t1`.`order`, `t1`.`level`, `t1`.`dynamic`, `t1`.`access`, `t1`.`notify`, `t1`.`contacts`, `t1`.`custom`, `t1`.`type`, `t1`.`updator`, `t1`.`created`, `t1`.`updated`, `t1`.`dependent`, `t1`.`actual_end_date`, `t3`.`users_user_id` as `t3_users_user_id`, `t3`.`type` as `t3_type`, `t3`.`perc_assignment`, `t3`.`user_task_priority`, `t4`.`login`, `t4`.`username` FROM `tasks` `t1` INNER JOIN `projects` `t5` ON t5.project_id = t1.projects_project_id INNER JOIN `user_tasks` `t3` ON t3.tasks_task_id = t1.task_id INNER JOIN `users` `t4` ON t4.user_id = t3.users_user_id [Thu, 03 Feb 2022 13:05:22 +0100] Error 2: WHERE de v_resource: [Thu, 03 Feb 2022 13:05:23 +0100] Error 1: URL ejecutada: /project2/timeline_ajax_event.php?start=2022-02-01T00%3A00%3A00%2B01%3A00&end=2022-03-01T00%3A00%3A00%2B01%3A00 I hope you find it useful and for any help or suggestion you can contact me through my email fernandohumanes@gmail.com
|
|