Finding the Current Address in a C Program

Let’s say for some reason you don’t have a disassembler and you wanted to find the address of a place in your program. This is useful for things like finding out how the size of a function, stack, or some code.

There are many ways to do this.

Probably the easiest way is to use GCC, a free compiler.

int main()
{
    int c;
 
    here:
    c = 5;
 
    printf("Address: %p", **here);
    return 0;
}

Read the rest of this entry »

Leave a Comment


Debunking Google’s Internet Optimization Tips

Google recently published a website called Let’s make the web faster.

Aimed mostly at newbies, they have a few tips that made people cringe despite having Google’s Seal of Approval. We will look at some of these optimizations and see if they really help.

spoiler

Micro-optimization

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. – C.A.R. Hoare

Read the rest of this entry »

22 Comments


Tips for Monitoring PHP

Just a couple hours ago, you may have noticed that this website was showing blank pages.

For some reason, PHP decided to stop working. Every PHP page was blank. I simply restarted it, and it worked again.

Unfortunately the error-logs are disabled for PHP in the default “production site” configuration. So be sure to enable that option.

Another option is to use Monit to monitor whenever PHP stops working. The trick is to use the “checksum” option:

[Usual monit php configuration here]
  if failed host www.codexon.com port 80
    protocol http and request "/monit.php"
      with checksum 5eb63bbbe01eeed093cb22bb8f5acdc3
      then restart

Where checksum is the MD5 value of the file. Then we create monit.php.

<?php
echo "hello world";
?>

So whenever PHP starts choking and serving blank pages, Monit will restart your PHP for you.

For those interested, this is the PHP I am running. All of which are from the Ubuntu 9.04 repository.

PHP 5.2.6-3ubuntu4.1 with Suhosin-Patch 0.9.6.2 (cli)
(built: Apr 23 2009 14:37:14)

APC 3.0.19-2

1 Comment


Benchmarking Browsers with Real Websites: Chrome, Firefox, Opera, Safari, IE

(An improved benchmark is being developed. A link to it will be here when it is completed.)

When it comes to a browser benchmark people act like this:

xkcd

The problem with browser benchmarks today is that they are extremely synthetic. A majority of them are Javascript only because its easier to test.

Read the rest of this entry »

47 Comments


How To Not Make a Web Counter

You might have noticed that the database loading times on here have doubled.

I looked at the database and had a true WTF moment.

sql

In as little as 1 week a WordPress plugin created 25,660 entries of visits, each one recording 1-5 visits.

Amazingly, this is one of few web counter plugins available for WordPress, and it even has over 17,000 downloads.

Update
I am currently helping the author debug this problem but for now I have already switched to another plugin which cut down database query time by 300%.

Leave a Comment