Live dump of HTTP request/response headers

Run on the machine in question:

live HTTP response headers
tcpdump -v -n -S -s 0 -A 'tcp src port 80'

live HTTP request headers
tcpdump -v -n -S -s 0 -A 'tcp dst port 80'

In case of nginx being the proxy use ‘lo’ interface:
tcpdump -v -n -S -s 0 -A 'tcp src port 80' -i lo

Posted in Uncategorized | Tagged | Leave a comment

Making an SSH tunnel to a third machine behind the middle one

ssh -L 8080:host3:80 -N user@host2

Then you can use localhost:8080 to open host2:80

Posted in Uncategorized | Tagged | Leave a comment

Behat: Setting cURL options with Guzzle and Goutte

If when running your Behat tests on a https website you ever seen these errors:

[curl] 51: SSL: certificate subject name ‘ubuntu’ does not match target host name ‘mycoolwebsite’


[curl] 60: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [url]

then you might want to set up Guzzle (PHP HTTP client and framework) and Goutte (screen scraping and web crawling library for PHP) in a way that it ignores strict SSL rules.

When you use Mink Goutte browser emulator it uses Guzzle to make requests and that actually uses cURL to archive that. To pass cURL parameters to Goutte you need to add them into curl.options section of default/extensions/Behat\MinkExtension\Extension/goutte/guzzle_parameters. You will need to set ssl.certificate_authority to system as well, otherwise the Guzzle\Http\Client::initSsl will reset CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER parameters to some other values.

So let’s modify your behat.yml according to this:

                 CURLOPT_SSL_VERIFYPEER: 0
                 CURLOPT_CERTINFO: 0
                 CURLOPT_SSL_VERIFYHOST: 0
              ssl.certificate_authority: system

After this pull request will get merged you will be able to just do:

              ssl.certificate_authority: false

After that you won’t see any SSL errors. Bingo!

This was tested with behat v2.5.1, mink-goutte-driver v1.0.9 and guzzle v3.7.4.

Posted in Uncategorized | Tagged , | Leave a comment

Namespaces in PHP

For a while I have not been using namespaces in PHP but the time has come.

In this article I mostly explain namespaces to myself but if you find this useful that’s good as well.

Working with several projects lately I noticed that third-party libraries are often used and you may have a situation when you want give a class or a function the same name used in other library. This, and ability of shortening class names to avoid names like Zend_Translate_Adapter_Array, namespaces exist for.

Not sure about you but I only consume information from good examples, so here they are.
Continue reading

Posted in Uncategorized | Tagged | 1 Comment

Fixing eAccelerator “open_basedir restriction. in Unknown on line 0″ error

If you are using PHP eAccelerator with open_basedir enabled you could have huge amount of these notices in your PHP log files:

open_basedir restriction. in Unknown on line 0

The reason behind it that at the moment eAccelerator tries to open the cached file which is usually in /var/cache/eaccelerator while open_basedir directive is still active and prevents it from doing so.

I don’t know why it is not fixed yet in the next release of eAccelerator but there is a bug about it.

Patch for v0.9.6.1 is there, but just in case, I put it on my host as well. You can download it here.

Having the patch handy, compile and install eAccelerator as usual, just patch it first:

root@video:~# cd eaccelerator-
root@video:~/eaccelerator- patch eaccelerator.c eaccelerator.c.2.patch
patching file eaccelerator.c
root@video:~/eaccelerator- phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
root@video:~/eaccelerator- ./configure
root@video:~/eaccelerator- make
root@video:~/eaccelerator- make install

Then create /etc/php5/conf.d/eaccelerator.ini:


Create cache directory

mkdir -p /var/cache/eaccelerator

Restart apache

/etc/init.d/apache2 restart

To check that it is used in CLI PHP, do

root@video:/etc/php5/conf.d# php -v
PHP 5.3.2-1ubuntu4.7 with Suhosin-Patch (cli) (built: Jan 12 2011 18:36:55)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator

To double check it in Web, you may need to create a phpinfo file.

Tha’s it, after that you should not have any more open_basedir notices

Posted in Uncategorized | Tagged , , | 1 Comment

Chmod files but not directories and vice versa


find top/directory -type f -exec chmod 0644 '{}' \;


find top/directory -type d -exec chmod 0755 '{}' \;
Posted in Uncategorized | Leave a comment

Installing PHP 5.3.3/5.3.4/5.3.5 on Ubuntu 10.04

One other problem I faced recently was a very strange Segmantation fault in unit tests which was very difficult to trace.

The problem was fixed by upgrading to PHP 5.3.3.

Unfortunately Ubuntu guys are quite slow of updaing packages so to get PHP 5.3.3 under Ubuntu 10.04 LTS do:

add /etc/apt/sources.list.d/php533.list file with:

deb lucid main 
deb-src lucid main

in it.


apt-get update
apt-get install php5

And you’re done!

If you want to fix apt-get warnings, you need to add they key specified on this page: (look under Technical details about this PPA->the Signing key-what’s this)

Posted in Uncategorized | Tagged , | 11 Comments

Find and replace contents of files recursively

find ./ -name '*.pm' -exec sed -i -e 's/oldtext/newxtext/' "{}" \;
Posted in Uncategorized | Tagged | Leave a comment

Configuring your OpenVZ containers and backing up using vzdump

The main parameter I’ve toched so far is:

privvmpages (Private VM Pages in webvz)- RAM size in memory pages. Usually memory page is 4Kb, so to give your container 256Mb, set it to 65536
(Guaranteed Minimum CPU in webvz)

installing vzdump to create backups:

apt-get install liblockfile-simple-perl

and make it restart automatically after rebooting inside the system:

put a “touch /reboot” in /etc/init.d/reboot (function do_stop())

Posted in Uncategorized | Tagged | Leave a comment

Installing and using Openvz & Webvz on Ubuntu 9.04

That worked for me:

sudo apt-get install vzctl vzquota
dpkg -i linux-image-2.6.26-2-openvz-686_2.6.26-25_i386.deb

Then you need to load into that kernel using grub and you are basically done:

alex@ubuntu:~$ uname -r

To install webvz then do:

apt-get install ruby rubygems libsqlite3-ruby sqlite3 irb libopenssl-ruby libreadline-ruby rdoc
gem install -v=2.3.2 rails

And after that, if you just run it:

ruby start/server
=> Booting WEBrick
=> Rails 2.3.2 application starting on
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-11-07 16:39:32] INFO  WEBrick 1.3.1
[2010-11-07 16:39:32] INFO  ruby 1.8.7 (2008-08-11) [i486-linux]
[2010-11-07 16:39:33] INFO  WEBrick::HTTPServer#start: pid=5129 port=3000

Download a template from and put it into /vz/template/cache directory, do not unpack though.

Now you can just go into webvz’s interface by using, e.g. and admin/admin123, you can create a new VE from there.

You’re done!

This post has beed used: installing openvz

Posted in Uncategorized | Tagged , | Leave a comment