BrodaNoel Posted October 16, 2013 Share Posted October 16, 2013 Hello everybody. First: Sory for my english. I'm searching a way to know wich lines of files are executed in all the request... Or something like that. Example: If we have this code: line 01: <?php line 02: function foo(){ line 03: echo 'Hello'; line 04: return false; line 05: } line 06: line 07: echo 'We are testing'; line 08: foo(); line 09: echo 'end of script'; line 10: ?> I need get the lines and the files executeds... For example, a log-file with this information: file index.php lines executeds: 07, 08, 02, 03, 04, 09, 10 Or something like that... I don't know... Anybody can help me? Tnks! Noel Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/ Share on other sites More sharing options...
vinny42 Posted October 16, 2013 Share Posted October 16, 2013 Look for xdebug, that can generate code-coverage reports that tell you which lines have been executed. But, it's much more useful to use an IDE like phpstorm or netbeans, then you can start a stript and pause it to see where what the scripts is doing, and step through the script line by line and see what all the variables etc contain. Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454136 Share on other sites More sharing options...
BrodaNoel Posted October 16, 2013 Author Share Posted October 16, 2013 (edited) Oh! Very well. It's like I need... But, the Code Coverage of XDebug only talk me wich lines has been called, not in wich order, or if any line has been executed more of one time. Can you help me with that? I'm looking the documentation, but, I can't see anything that solve my problem. However, if the XDebug library can do that, obviously can do that I need... Maybe with a "little" change. Tnks! Edited October 16, 2013 by BrodaNoel Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454148 Share on other sites More sharing options...
Ch0cu3r Posted October 16, 2013 Share Posted October 16, 2013 Maybe debug_print_backtrace may help you? Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454151 Share on other sites More sharing options...
vinny42 Posted October 16, 2013 Share Posted October 16, 2013 A backtrack can't go back indefinately, there is a limit to how many calls you can see, and even then you have to count them manually. It's either going to be xdebug, wich also won't trace indefinately, or Zend Studio, which costs a bundle. With xdebug and netbeans you can at least see what you code is doing by stepping through it. Perhaps you should tell us a bit more about what you are trying to see in this information? Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454155 Share on other sites More sharing options...
BrodaNoel Posted October 17, 2013 Author Share Posted October 17, 2013 (edited) Look, my idea is create a project like "code-coverage", but, with a little diference: This project is a library. When this library is activated in a web-site in development-environment, the library will create a visual-log in HTML format + very much CSS and jQuery and more... The idea is: When a test-user visit the site, when the request is finaliced, he can open example.com/log.html and see all the lines executeds in the last request... And then, he can understand all the "way" of the request... Very usefull for a new developer when he need understand the site... Or, for another example: to I can explain how to work a site to a other developer, without open the code. Do you understand? Sory, sorry toooo much for my english. Edit: The problem with debug_print_backtrace, is: this function only show the calls to functions... I need know all the lines executeds. In spanish: Quiero hacer una libreria para poder visualizar todo el camino que recorrió el request (linea por linea) de manera GRAFICA, con CSS, HTML, y demas. Para hacer esta librería, necesito conocer el recorrido exacto del codigo fuente. Edited October 17, 2013 by BrodaNoel Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454335 Share on other sites More sharing options...
vinny42 Posted October 17, 2013 Share Posted October 17, 2013 I can't read spanish. I understand what you want to do; log the execution of a script line by line so you can debug the script by looking at the log. ZendStudio can do this and the logs are *huge* because if you go into a loop of twenty lines, that executes 500 loops, you get 10000 lines in your log, which makes it unreadable. This is why xDebug aggregates the results and only tells you how many times each function was called. This is much more usefull information than a full line-by-line log. If you want to know which lines are executed it is also much more usefull to use a breakpoint and step-through the code. So yes I understand what you want an no you can't do that and you porobably shouldn't anyway :-) Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454341 Share on other sites More sharing options...
BrodaNoel Posted October 17, 2013 Author Share Posted October 17, 2013 Viiny... Why you tell me: "probably you can't do that", but also tell me "Zend Studio can do this". How ZendStudio can? Should be/exists a library to do this. What do you think? Is not important if the log is unreadable... My library will be the "magic" for solve this problem... I'm only need get the -unreadable- log and the next steps is my work. Again, sorry for my english. see you gays! And TNKS for all the replys (soo quickly!) Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454357 Share on other sites More sharing options...
AbraCadaver Posted October 18, 2013 Share Posted October 18, 2013 Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454377 Share on other sites More sharing options...
.josh Posted October 18, 2013 Share Posted October 18, 2013 Okay so how exact do you want this? Let's say you have the following: <html> <head> <script type='text/javascript' src='someScript.js' /></script> </head> <body> <?php include('db/connect.php'); $query = 'select param, value from table'; $result = $mysqli->query($query); ?> <script type='text/javascript'> var config = {}; <?php if ($result) { while ($row = $result->fetch_row()) { echo "config.{$row[0]} = '{$row[1]}';"; } } ?> runScript(config); </script> </body> </html> Show me exactly what you expect to see in the log file from this. Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454381 Share on other sites More sharing options...
vinny42 Posted October 18, 2013 Share Posted October 18, 2013 Why yo-u tell me: "probably you can't do that", but also tell me "Zend Studio can do this". How ZendStudio can? Should be/exists a library to do this. What do you think? ZendStudio uses a binary plugin for PHP that hooks into PHP itself, so you cannot do this unless you also write a plugin in C++ and compile it and load it on the webserver. Is not important if the log is unreadable... My library will be the "magic" for solve this problem... I'm only need get the -unreadable- log and the next steps is my work. My point is: you cannot make the log readable, there is simply too much data to make it understandable. Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454401 Share on other sites More sharing options...
BrodaNoel Posted October 18, 2013 Author Share Posted October 18, 2013 (edited) Okay so how exact do you want this? Let's say you have the following: <html> <head> <script type='text/javascript' src='someScript.js' /></script> </head> <body> <?php include('db/connect.php'); $query = 'select param, value from table'; $result = $mysqli->query($query); ?> <script type='text/javascript'> var config = {}; <?php if ($result) { while ($row = $result->fetch_row()) { echo "config.{$row[0]} = '{$row[1]}';"; } } ?> runScript(config); </script> </body> </html> Show me exactly what you expect to see in the log file from this. Hello! Suppose that: the db/connect.php file, have 18 lines (without any function) The log will be like that (all the following lines, will be into the log file) index.php - lines: 7 db/connect.php - lines: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 index.php - lines: 8,9,14,15,16,16,16,16,16,16,16,16,16,16,17,18 END OF FILE. Look, if "->query()" or "->fetch_row()" are functions in a php-library, the lines executeds when its functions are called should be writed in the log file. then, the log will look like that: index.php - lines: 8,9,14,15,16 some-library.php - lines: xx,xx,xx,xx index.php - lines: 16 some-library.php - lines: xx,xx,xx,xx index.php - lines: 16 some-library.php - lines: xx,xx,xx,xx index.php - lines: 16 some-library.php - lines: xx,xx,xx,xx index.php - lines: 16 some-library.php - lines: xx,xx,xx,xx index.php - lines: 16 index.php - lines: 17,18 Soo, only the php lines executeds will be writed in the log-file. The library that I whant to create, read this log and create a .html SOO BEAUTIFULL with rectangules with beautifuls background and animations with jQuery and soo much more "styles" and bla bla bla... Vinny42, if the log that Zend create, is very very unreadable (for example: a ninary file), i understand, but, if the file is unreadable but with a pattner like the example over, this log can help me. If ZendStudio have a library that I can "include" in php.ini (or in somewhere), this can help me to get my tarjet! If the log is unreadable for a humans, that does matter. Only will be readable for my library (or my library will learn to read this log) and, the next work will executed for my library to create/make a new log readable and renderizable for browsers. SOOORRY for my english. EDIT: The title for this topic will be: "How yo know all the lines executeds in a php request" Edited October 18, 2013 by BrodaNoel Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454432 Share on other sites More sharing options...
.josh Posted October 18, 2013 Share Posted October 18, 2013 okay but you also mentioned html, css, etc.. so is it also supposed to show line by line those things too? Also, I asked that you show me exactly what you want to see. The point of this exercise is that you aren't being very clear, and it's not just the language barrier that's making you unclear. Pretend you have already made the script that does what you want. Take the code I have given and generate the log file and output. You will have to do this manually or by hand of course, since you don't actually have the script yet. Then post it, so that we have a very clear "before" and "after" picture. Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454437 Share on other sites More sharing options...
BrodaNoel Posted October 18, 2013 Author Share Posted October 18, 2013 (edited) No no no... Is my english, I cant explain me correctly. My library will have 2 steps. The first steep, is create a log file "unreadable" (OR get the log that is create for the library of Zend). The Second Steep: is read all the log (in the log only have informations about the php lines executeds), and CREATE ANOTHER file with .html extension when we cann see all the request "beautiful". I can explainme perfectly, soo, you need understand that: The second steep, is my work... My BIG problem is HOW TO get a log with this information: "The number of the lines executeds in the last request", but not only the lines that were executed, also the order in which they were executed. And if a line was executed more than 1 time, I also see it in the log. Soo, if i can get that, the NEXT is easy, and is my work. Do you understand? I will create an example of the result. But, it is unnnecesary. Edited October 18, 2013 by BrodaNoel Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454439 Share on other sites More sharing options...
BrodaNoel Posted October 18, 2013 Author Share Posted October 18, 2013 When we get the log, the library read this log and generate a file with html. This file, opend in a browser generate this HTML: Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454443 Share on other sites More sharing options...
BrodaNoel Posted October 18, 2013 Author Share Posted October 18, 2013 The library, if is activated in the server, will generate a LOG for each request with information about the lines executeds (only php lines). The library, for do that, do: "append lines in a log file" THen, when a developer (or anybody) open: "example.com/the-library/seeTheLog.php" And, this file (seeTheLog) willl read the log file, and will generate a HTML beautifull and readable for look all the lines executeds in the request. Soo, this second steep is like a system with input, process, and output... Input: the unreadable log process: my magic output: some like the over photo.. some like class diagrams (http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Diagrama_de_clases.svg/380px-Diagrama_de_clases.svg.png). BUT NOT DIAGRAM OF CLASS,!!! This will be a diagram "of files and his lines executeds". Now, understand? Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454447 Share on other sites More sharing options...
vinny42 Posted October 18, 2013 Share Posted October 18, 2013 Like I said four times: you cannot do this in PHP code, you must write a binary library to plug into PHP. And I understimated xdebug, it can create these logs too: http://devzone.zend.com/1135/tracing-php-applications-with-xdebug/ and as you can see from that, the logs are *huge*, there are thousands of lines in each log and like I said; if the script goes into a loop you can easily get millions of lines of executed code. You are simply never going to make that visible. Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454455 Share on other sites More sharing options...
kicken Posted October 18, 2013 Share Posted October 18, 2013 It sounds to me like what you want is basically the output generated by the XDebug Profiler. It will give you a file containing the line #'s, functions called, and timing data. You can then take that and generate your pretty-picture showing what happened (or just use one of the already existing tools for that). Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454458 Share on other sites More sharing options...
BrodaNoel Posted October 18, 2013 Author Share Posted October 18, 2013 Tnks Vinny! I will look if i can do that with C. Kicken, I will see XDebug profiler... Tnks! Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454480 Share on other sites More sharing options...
Solution trq Posted October 19, 2013 Solution Share Posted October 19, 2013 There is also facebook's xhprof. https://github.com/facebook/xhprof I've used it in the past and while the code sux, it works quite well and does pretty much what you have described. Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454510 Share on other sites More sharing options...
BrodaNoel Posted October 21, 2013 Author Share Posted October 21, 2013 Hello TRQ! That look well! In the next days I will try to use this library. I think that (xhprof) is the library that I want to create. So, the work is done When I will use the library, I will comment here the results. Tnks Quote Link to comment https://forums.phpfreaks.com/topic/283019-how-to-know-all-the-calls-in-php/#findComment-1454761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.