I want to log what lines per file was run in php. Xdebug can do that, thats all I know. How to do this?
I guess you want a code analyzer, here is a good thread about this
Related
Good day guys..i'm currently working as an sys ad assistant. i just want to know if how can i know that a file from a directory(and it's subdirectory) has been modified..do i need to put every php code on a database? and is there a possibility to know which part of the file has been modified?thanks. please help.
Not sure what you mean by the database reference... but in general, if you know a file's creation date, you could check to see if filemtime is different from that. I'm a bit leery of using file modification times however; I've found some instances in which they were misleading, so take this with a grain of salt.
Outside of having a previous version of the file (via backup or a RCS), I can't think of how you'd see what part was modified.
Since you are working as sys ad assistant, I presume you can also use python.
If so, consider using watchdog library. I think it is a perfect fit.
When you're at it, you can also use programatically, with python, linux/unix diff command.
For this, you can also check out python sh module, which enables you to call diff from your python code.
php is hardly perfect solution for your sysadmin needs.
And python may be even easier to learn than php.
Use filemtime() which will give you the last time that the file was changed.
But you cannot know any made differences as far as you aren't running a version control system.
I am developing a browser based game and i'd like to know which functions take the most time to process and so on.
Does anyone of you guys know what I can start with ? Using PHP 5.3
It sounds like you want xhprof. It excels at profiling.
There's a profiler in XDebug.
There's also one called PHP APD
I was wondering if there was a way to know where the script stopped (ie: file + line), which would be useful for debugging or for removing stupid 'exit' calls lost somewhere in the code.
Thanks in advance
Wrong (and I'm sorry for not testing it first): You could use register_shutdown_function in conjunction with debug_backtrace.
See here for a duplicate of your question: Fastest way to determine where PHP script exits .
If you want to remove exit from the script, try using PHP Code Sniffer PEAR package http://pear.php.net/package/PHP_CodeSniffer
Just create a sniffer to find out where all the exits are in the code (you get a report of file and line).
If you want to find out what line a script stopped at, use a debugger and you can get a stack trace to find out the last line a script executed too (Xdebug is easy to use and set up). Any debugger is going to severely hinder performance as it needs to manage more memory.
I'm not sure what IDE your using (if any), but this would be trivial using xdebug. I personally use it with netbeans and it works great although it is a bit tricky to setup. It will let you walk through your code step by step and show exactly where it is exiting.
I've just inherited a project, and been told that an entire folder, "includes/" needs to be removed due to licensing issues -- We don't have the right to redistribute the files in that folder, so we need to cut our dependencies on them, and fix whatever breaks. I've been told "Less than 5% of the lines in that folder are ever even called by our program", but I have no way of verifying this.
There are about 50 files in the folder, each with a couple hundred lines of code. There is no unit testing currently in place. There's one master file, include.php, that require()s all 49 other files, so I can't just grep for any file doing import() on includes/.*.
This is about as much detail as I've really figured out at this point. I spent all last week reading through the files in the includes/ folder, and it won't be hard to rewrite any of this, but I'm having trouble deciding where to start. I tried deleting the folder and slowly fixing things that break, but I'm afraid that this route will cause me to miss some crucial functions in my rewrite.
Can anyone point me in a direction to get started? Are there tools that will simplify this process? I'm looking at xdebug right now, but I'm not sure exactly how I'd use it for this.
You may want to search for "php code coverage." That should help you figure out what code is used. For instance, this appears like it might help:
http://www.xdebug.org/docs/code_coverage
Your initial approach isn't bad at all. It's certainly a reasonable place to start:
delete that code that isn't allowed.
try to run what's left.
if things break: create a stub for a method that is now missing, and set it to return some sensible "default" value for now.
goto 2.
Then, itemize all the things that were missing, and make a sensible schedule to re-implement each thing.
I would start by grepping for files that reference include.php. Check through them if they're manageable, one by one. Then I'd grep for each of the functions in the /include/*php files. See if they're called anywhere, find 'em, replace 'em.
Because PHP is so dynamically typed, I don't think there's going to be a tool for this.
(Eagerly awaiting someone to prove me wrong because I have similar tasks all the time... )
See SD PHP Test Coverage Tool. It will provide a visual view of what code actually executes, as well as a report on what parts of files are used (including "no parts", which is your cue that
the code is a likely candidate to delete).
It doesn't require any hand-modifications of your code, or any unit tests to run it.
To answer my own question, I wound up using xdebug profiler to do the job, as I was initially investigating (after a friend's suggestion prompted me to take a second look).
In my /etc/php5/apache2/conf.d/xdebug.ini (on ubuntu 9.10), I set xdebug.profiler_enable=1 and xdebug.profiler_output_dir=/var/log/xdebug/, then loaded up the resulting cachegrind files with KCacheGrind and just ran a search on filenames for "includes/".
Now I have a mountain of work ahead of me to remove all this, but at least I've got a good overview of what I'll be modifying!
Hi i'm used to programming with ASP.Net but i got just landed a project doing PHP development.. My question is this, in ASP.Net if you make changes in the code behind you have to recompile the app before uploading. Is it the same with PHP? I know it's not a compiled language but I want to know if I can make changes to the PHP code in a single file and upload and see my changes?
Thanks in advance!
No, you don't have to recompile. So, yes, you can immediately see your changes. It reads and parses each file as it is called which makes things quite a bit simpler.
In PHP, you don't need to recompile before uploading. Simply change the files and that's it.
PHP is an interpreted language, there is no compilation(*). So just uploading the changed code, and refreshing the browser is enough.
(*) there are compilers around to speed up execution, but that is a different matter.