I have two xdebug trace files, about 25 MB each. One of them led to an error and I'm trying to find the spot where the two execution sequences deviated. The problem is that there are a bunch of irrelevant differences between the two files that I want to ignore, such as remote port numbers, query times and other database statistics.
My first attempt at solving this was to open the trace files in excel and remove the execution times which are obviously different most of the time. Then I tried using compare/merge apps to get rid of the other irrelevant differences. For example I replaced the remote portnumbers in both of the files with a placeholder string PORT_NUMBER. Some of the differences are repeated again and again so I need to be able to search and replace globally. The problem is that all of the apps I've tried are extremely slow and often crash. They can't handle rendering with word wrap, search and replace or even simple editing with files this big.
I've tried many compare/merge apps including DiffMerge, WinMerge, KDiff3, Meld, Notepad++, Eclipse and Visual Studio Code. I don't think that using diff and sed together would work, because I need to see in-line differences and jump to different parts of the large file quickly. I also would have to copy and paste the differences from diff to use in sed and they use another terminal for sed. There are also special characters and extremely long lines, so I don't think sed is a good option.
I'd like to find a way to use the trace files to find the point of deviation in the execution sequence.
The best way to do this, is by having two "computerized" trace files (it's xdebug.trace_format=1). This format is tab separated, which makes it easier to write a script that goes through them and does the comparison. You can ignore arguments to methods/functions etc too, as well as even compare return values if you wish to do so.
There is a mini script in Xdebug's contrib directory (https://github.com/xdebug/xdebug/blob/master/contrib/tracefile-analyser.php) that shows a little about how to do that.
If you can't create them again, then you are going to be up for a much harder task. The first thing I would do is to strip out all the arguments (with a regexp). VIM would probably be your best bet handling two 25MB files.
Related
I've got a few huge XML files, and I cut a few rows out, so I could have a manageable-sized file on which to test my parsing script, written in php. There is a lot of nesting in the XML file, there are a lot of columns, and there are a lot of blanks, so writing the script was this huge ordeal. Now, I'm hitting my php memory limit on the full-sized XML files I want to parse.
Now, one thing I've considered is temporarily upping the php memory limit, but I need to rerun this script every well... week or so. Also, I don't have the best system. Running it hot and setting it melt is an all-to-real possibility and one of my "perfect storms".
I also considered attempting to learn a new language, such as perl or python. I probably could use to know one of these languages, anyway. I would prefer to stick with what I have, though, if only in the interest of time.
Isn't there some way to have php break the XML file up into manageable chunks that won't push my machine to its limit? Because every row in the XML file is wrapped by an ID column, it seems like I should be able to cut to the nth row closure, parse what was sliced, and then sleep, or something?
Any ideas?
So, I inherited some really bad code and am currently just trying to refactor it to the point of functionality before completely overhauling it. One of the problems is that the original programmer set posts and sessions like this:
$_SESSION[somename]
$_POST[somevar]
instead of:
$_SESSION['somename']
$_POST['somevar']
It seems to be causing problems throughout the site. Is there a fast way that I can recursively find and replace these types of variables? I'm using a unix box, so not sure if there's a way to do that from the command line or if I should write a php script? They're everywhere and obviously are named different, so I would need to find any variable that does not have the quotes and replace it with the same string that does?
I would use sed for the job. I would then search for $_POST[(something)] and replace with $_POST["(something)]. Remember to go as unambiguous as you can. Also, remember to take a backup before trying to mess with it. Afterwards I would try running all the php files with "php [file]" to check if they are at least syntactically correct.
I know that it is possible to use Ctrl+] to jump to a definition in Vim and this can work in conjunction whith either ctags or Cscope. I am looking for a more accurate alternative to both ctags and Cscope when working PHP. Sometimes there are multiple possible results to choose from or false positives. I only want to jump to the actual definition of whatever is under the cursor. Ideally this should work for variables, functions, constants, and classes.
I don't see why this can't be done by analyzing the files. I have finally overcome just about every other annoyance/misunderstanding I have with Vim by learning and customizing, so if I could nail this one it would be awesome.
Also, do other's agree that Cscope and ctags are not accurate enough for PHP or am I doing something wrong?
UPDATE
4 years later, I am still using Vim with PHP, and still having this problem. I have tried eclim, ctags, exubarant-ctags, universal-ctags, and cscope. I have tried passing various arguments to these programs to get them to generate better tags. The experience is very poor for all of these options.
But I understand the problem much better now. There might be nothing wrong with the tags generated by these programs. The problem seems to be that when you press Ctrl + ] in Vim or Neovim, it just looks for a tag by that name. It is not looking at the context of the file you are editing to see which tag by that name it should use. It does not even understand what language you are editing, and look for tags from code in that language.
Is there a way to make vim search through the tags file more intelligently, based on the context, and then jump to the most likely location? You know, like what would happen inside a good IDE?
As a C++ developer I had similar issues for a long time. Until, that is, I reorganized my approach to using tag files under Vim a few years ago. The trick that made it work for me was to generate separate tag files for different slices of code: my project, various external code libraries, etc... I then had to set the 'tags' option to look for the files in a priority order, with my local code project files coming first and then working outward from there with the system header files being LAST.
In my case, I had separate tag files for each of these and listed in this order in the 'tags' option:
My local project
Any other project that this project uses
System-bundled libraries (boost)
System-bundled libraries (WxWidgets)
System libraries (C++ standard libraries)
System libraries (all else)
I'm not a PHP developer, but again the main mistake I made for a long time was just generating a single tags file FOR EVERYTHING. I'd have upwards of 30 tags to search through many times (using the :tag command). If you generate multiple tags files you have much more control over the search order of tags and thus what tags in which files are found.
See if that works for you. It did for me.
To improve ctags for PHP, you could create tags file like this:
#!/bin/bash
cd /path/to/framework/library
exec ctags-exuberant -f ~/.vim/mytags/framework \
-h ".php" -R \
--exclude="\.svn" \
--totals=yes \
--tag-relative=yes \
--PHP-kinds=+cf \
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'
then load the tags
:set tags=~/.vim/mytags/framework
taken from my blog post
You may also wanna take a look at eclim.
This could utilize eclipse's completion feature, and it should work fine for PHP (I haven't tried).
Struggled with the same problem for a long time until I found the LanguageServer for PHP.
It provides features like GoToDefinition, ShowReferences, Tags at current document etc. It is integrating okay with fzf right out of the box.
Things I don't like about it:
autocompletion is slow compared to other frameworks like padawan
it doesn't cache (yet) your project's index, which means, it has to reindex when you open neovim. Nevertheless, you can use the GoToDefinition functionality while it's still indexing.
Quick setup for vim-plug:
Plug 'autozimu/LanguageClient-neovim', { 'do': ':UpdateRemotePlugins' }
Plug 'roxma/LanguageServer-php-neovim', {'do': 'composer install && composer run-script parse-stubs'}
autocmd FileType php LanguageClientStart
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
nnoremap <silent> gr :call LanguageClient_textDocument_references()<CR>
Best solution I've found so far.
More of a workaround, but if you press g CTRL+[ instead of just CTRL+', you get a list of all the tags of that name, and you can select which one to jump to.
PHP is not a well designed language, and it is not statically typed. As such, the foundation is just not there for any good tools of this kind to be made that would be practical to use in real world projects. IDEs, language servers, and Vim and Neovim plugins can only know as much about the code as the language allows. It is possible to write very consistent code in PHP with as much types as possible and that only utilizes a limited subset of the language, such that tools could understand it. However if your team is capable of writing that good of PHP code, they are good enough to rewrite the code in a more well designed language that can support even better tooling, something like Kotlin which also has great IDE support.
I'm a Web developer. I had been using a variety of editors and ide-s for web development(php, javascript,html,css) six months before I decided to learn a true editor and started using emacs. I learned all the basics, used the starter kit, practiced using buffer, windows etc..
I got a grip in 2 months. A month ago I started learning about vim and I found a lot of plugins to achieve the things I want. I'm finding to achieve the same effect in emacs you have to do a lot(for php/js/css/html editing).
Here are the list of things I'm finding hard. Note: These things are related when I'm editing php/html/css/js.
syntax hightlighting(php/smarty). -- the php major mode is too old and it always highlights html/smarty inside the php code incorrectly.
I love ido-mode but i couldn't find how to define a project and fuzzy match files inside the predefined directory
I can setup nerdtree plugin to get a quick overview pane on the left with the files I'm working on with vim. But configuring speedbar and source code browser in emacs is bit difficult.
Context aware completion I really don't know how to do that. I have seen something like that in clojure mode where it shows the definition of a method in the messages area.
Tags-generation: The tags generated with excrebant-ctags does not always work with php. In vim it is easy I can open a file containing the definition right under the cursor.
Manual lookup I want to lookup the manual for a particular word under the cursor without opening the browser (in the messages area(mini-buffer)).
I love ido mode and switching b/w files in tramp,buffers,local files using ido-mode.
Can anyone point me in the right direction? Do you use emacs for same kind of editing I do? What is your work flow?.
nxthml-mode is the ultimate mode for web development.
You can easily define a project in terms of its VCS or .dir-locals.el with find-file-in-project.
Fuzzy matching is called flex matching in ido. You can enable it with:
(setq ido-enable-flex-matching t)
I've never had any problems with ctags, manual lookup is trivial to implement...
Manual lookup I want to lookup the manual for a particular word
under the cursor without opening the browser. (in the messages area
(mini-buffer))
It sounds like you are after eldoc-mode support for PHP? (enable it on a lisp file to see example)
;; Major modes for other languages may use ElDoc by defining an
;; appropriate function as the buffer-local value of
;; `eldoc-documentation-function'.
A search for eldoc-documentation-function and PHP turns up this:
http://www.emacswiki.org/emacs/php-doc.el
I like Emacs for small projects and quick editing.
There are things like C-x ( to make a repeat-macro, delete-matching-lines, describe-function (...), apropos, the quick C-x 2 to split window, the warnings (text was edited elsewhere do you really want...) and the quick Lisp fix in .emacs that make me having an Emacs open at all times.
But for bigger projects, when you want to hover a keyword and have its definition, the call hierarchy, the updated syntax highlighting etc... Emacs is not enough for me. I use Eclipse (which is slow and not perfect anyway for C C++).
syntax hightlighting(php/smarty). -- the php major mode is too old and it always highlights html/smarty inside the php code incorrectly.
The simplest and best way to manage mixed languages in one single buffer is to clone the window showing it with C-x 4 c and use different major modes for each window showing this single buffer, for example, one window with the php-mode, one window with the nxhtml-mode to correctly highlight the HTML syntax.
I am going to start working on a website that has already been built by someone else.
The main script was bought and then adjusted by the lead programmer. The lead has left and I am the only programmer.
Never met the lead and there are no papers, documentation or comments in the code to help me out, also there are many functions with single letter names. There are also parts of the code that are all compressed in one line (like where there should be 200 lines there is one).
There are a few hundred files.
My questions are:
Does anyone have any advice on how to understand this system?
Has anyone had any similar experiences?
Does anyone have a quick way of decompressing the lines?
Please help me out here. This is my first big break and I really want this to work out well.
Thanks
EDIT:
On regards to the question:
- Does anyone have a quick way of decompressing the lines?
I just used notepad++ (extended replace) and netbeans (the format option) to change a file from 1696 lines to 5584!!
This is going to be a loooonnngggg project
For reformatting the source, try this online pretty-printer: http://www.prettyprinter.de/
For understanding the HTML and CSS, use Firebug.
For understanding the PHP code, step through it in a debugger. (I can't personally recommend a PHP debugger, but I've heard good things about Komodo.)
Start by checking the whole thing into source control, if you haven't already, and then as you work out what the various functions and variables do, rename them to something sensible and check in your changes.
If you can cobble together some rough regression tests (eg. with Selenium) before you start then you can be reasonably sure you aren't breaking anything as you go.
Ouch! I feel your pain!
A few things to get started:
If you're not using source control, don't do anything else until you get that set up. As you hack away at the files, you need to be able to revert to previous, presumably-working versions. Which source-control system you use isn't as important as using one. Subversion is easy and widely used.
Get an editor with a good PHP syntax highlighter and code folder. Which one is largely down to platform and personal taste; I like JEdit and Notepad++. These will help you navigate the code within a page. JEdit's folder is the best around. Notepad++ has a cool feature that when you highlight a word it highlights the other occurrences in the same file, so you can easily see e.g. where a tag begins, or where a variable is used.
Unwind those long lines by search-and-replace ';' with ';\n' -- at least you'll get every statement on a line of its own. The pretty-printer mentioned above will do the same plus indent. But I find that going in and indenting the code manually is a nice way to start to get familiar with it.
Analyze the website's major use cases and trace each one. If you're a front-end guy, this might be easier if you start from the front-end and work your way back to the DB; if you're a back-end guy, start with the DB and see what talks to it, and then how that's used to render pages -- either way works. Use FireBug in Firefox to inspect e.g. forms to see what names the fields take and what page they post to. Look at the PHP page to see what happens next. Use some echo() statements to print out the values of variables at various places. Finally, crack open the DB and get familiar with its schema.
Lather, rinse, repeat.
Good luck!
Could you get a copy of the original script version which was bought? It might be that that is documented. You could then use a comparison tool like Beyond Compare in order to extract any modifications that have been made.
If the functions names are only one letter it could be that the code is encoded with some kind of tool (I think Zend had a tool like that - Zend Encoder?) so that people cannot copy it. You should try to find an unencoded version, if there is one because that would save a lot of time.