Archive for the ‘tech’ Category

PHP Fat Memory Manager Patch available

Wednesday, June 11th, 2008

My latest performance bottle-neck in PHP has been the frequent memory allocation/deallocation that happens on every request.  I’ve created a speed freak’s patch to help with this by pre-allocating memory and letting it persist across requests.  This removes the interaction with the kernel memory management, and the rest of the internal emalloc/efree calls are dealt with similar to that of a pool allocator.  It’s horribly memory inefficient in the hopes of making some CPU gains.  The patch for PHP-5.2.6 is available, I’d like to hear feedback about it’s success/failure in different environments.



Bash autocompletion + git = super lazy goodness….

Wednesday, April 30th, 2008

Lately I’ve been using some longer, and not very memorable, git branch names. I love bash completion and was hoping I could add items to this auto-completion dynamically on request. It turns out this is really simple to do. Thanks to this fab tutorial, a quick code snippet like this in my .profile and I’m all set.


_complete_git() {
  if [ -d .git ]; then
    branches=`git branch -a | cut -c 3-`
    tags=`git tag`
    cur=”${COMP_WORDS[COMP_CWORD]}”
    COMPREPLY=( $(compgen -W “${branches} ${tags}” — ${cur}) )
  fi
}
complete -F _complete_git git checkout

Now anytime I’m in a path with a .git directory, I can just use ‘git checkout [tab]‘ and I’ll git tag and branch auto-completion goodness.



Vim Diff

Thursday, February 21st, 2008

For a long time now I’ve wanted to have the current diff of my working copy highlighted in vim. This would help a lot when you’re working in complicated code and want your modifications to pop out in case you’ve missed something. Unfortunately none of the existing tools do exactly what I want, so with the advice of some co-workers I’ve hacked up the svndiff vim script and made it work with git just like I wanted. Now I can turn on or refresh the highlights with Ctl-D and diff against a different branch with “:D <branch>”.

http://tekrat.com/images/vimdiff.jpg


gitdiff.vim
—————
if exists(”loaded_gitdiff”) || &cp
finish
endif
let loaded_gitdiff = 1

map <C-d> :call <SID>Gitdiff()<CR>
map <C-g> :set nodiff<CR>
noremap <unique> <script> <plug>Dh :call <SID>Gitdiff(”h”)<CR>
com! -bar -nargs=? D :call s:Gitdiff(<f-args>)

let g:gitdiff_rev = ”

function! s:Gitdiff(…)
if a:0 == 1
if a:1 == “none”
let g:gitdiff_rev = ”
else
let g:gitdiff_rev = a:1
endif
endif

let ftype = &filetype
let tmpfile = tempname()
let cmd = “cat ” . bufname(”%”) . ” > ” . tmpfile
let cmd_output = system(cmd)
let tmpdiff = tempname()
let cmd = “git diff ” . g:gitdiff_rev . ” ” . bufname(”%”) . ” > ” . tmpdiff
let cmd_output = system(cmd)
if v:shell_error && cmd_output != “”
echohl WarningMsg | echon cmd_output
return
endif

let cmd = “patch -R -p0 ” . tmpfile . ” ” . tmpdiff
let cmd_output = system(cmd)
if v:shell_error && cmd_output != “”
echohl WarningMsg | echon cmd_output
return
endif

if exists(”s:killbuffs”)
2,9999 bdelete
endif
let s:killbuffs = 1
if a:0 > 0 && a:1 == “h”
exe “diffsplit” . tmpfile
else
exe “vert diffsplit” . tmpfile
endif

exe “set filetype=” . ftype

hide
set foldcolumn=0
set foldlevel=100
set diffopt= ” removed filler so we don’t show deleted lines
highlight DiffAdd ctermbg=black ctermfg=DarkGreen
highlight DiffChange ctermbg=black ctermfg=DarkGreen
highlight DiffText ctermbg=black ctermfg=DarkGreen cterm=underline
highlight DiffDelete ctermbg=red ctermfg=white

endfunction

“autocmd CursorHold * call s:Gitdiff()

—————

Tags:



Open Web Vancouver 2008

Monday, February 18th, 2008

It looks like my talk has been accepted at the Open Web Vancouver 2008 conference. I’m really looking forward to this as this will be my first conference that isn’t strictly PHP. There will be a wider range of topics including Ruby on Rails, Python, Javascript, and even some mobile technology.

I’m really impressed with the site organization so far, I’ve got an account that looks like it lets me update my talk summary and tags. The conference is also really reasonably priced at only $150 (+$20 for a t-shirt)! My talk will be the “APC @ Facebook” talk that I’ve given in the past, but of course I’m hoping to update it with some recent changes and hopefully some new features that I’ve yet to complete.

My name has also apparently made it under the title “Some of the big names you can expect to hear”, although my name is the only one where the hyperlink is on “Facebook” rather than my name. I guess I’m riding in on the coat tails so to speak. ;-)

Update:  Turns out somebody does read my blog and the “coat tailing” is no more, thanks!

Tags:



Experimental APC Binary Dump Support

Monday, November 12th, 2007

I’ve put up the Experimental APC bindump patch here.  This allows users to dump an architecture specific version of the APC cache and load it back up later on the same or identical machines.  I’d love to get feedback from people regarding bugs and use cases!



DC PHP 2007

Wednesday, November 7th, 2007

Just finished my talk on APC at the DC PHP 2007 conference.  Added a couple new slides and some patches I’ve released for APC, PHP and Apache.  You can download the slides here.  Thanks to all who attended!



PHP MySQL “typed” functionality

Tuesday, October 9th, 2007

If you’ve ever wanted to have the PHP MySQL functions return back PHP variables cast to something other than strings this patch is for you.  It’s useful for decreasing memory usage if you’re pulling down integer values for example, especially if you’re then storing them in a cache such as APC or MySQL.  Read the patch for details, download page is here.



PHP INI Includes

Tuesday, October 9th, 2007

I’ve posted a patch that should allow you to use include statements in PHP’s INI files similar to Apache.  This is useful when you have complicated server configurations that can be managed better via linked include files rather than a scan directory.  Let me know if you have any problems, the patch page/download can be found here.



Apache UnsetErrorDocument

Thursday, September 27th, 2007

Apache-1.3.x doesn’t provide a way for you to “Unset” an ErrorDocument directive to it’s original value.  I’m providing a patch that will add a “UnsetErrorDocument” directive to reset the value.  This could happen when you have multiple configuration files that need to override each other.  You can find more information and a download here.  (Credit for the initial idea goes to Lucas)



Apache Source Defense

Monday, September 24th, 2007

I’ve released a small patch (read hack) that can help to prevent source code from being displayed by Apache. In theory this will work for any handler, but in specific it was designed with PHP in mind. The patch is intended to be a last line of defense if Apache attempts to display code with it’s default handler say due to a misconfiguration. It essentially filters out files with the defined extensions so that they cannot be handled by Apache’s default handler. This means you’ll have to hardcode your extensions into the patch. Please feel free to use this, but I’m not responsible for it not working as advertised. Lucas has posted a blog post a blog post about how we use something similar at Facebook. I’ve modified it for public release so hit me up with any problems.
Available via the MIT License

Download: ap_source_defense.patch