iPhone G3 Connection Problems?

January 21st, 2009 Category: Latest Featured, iPhone
img_5857.jpg

A friend of me told about connection problems with his brand new iPhone G3 (I also have one, shrug. By the way, if anyone is wondering why I’m owner of G3: the responsible person was mentioned in the first sentence of this article. So I think in case of connection problems I’ll make him responsible – sue him, ha ha!). During phone calls it happens that the connection is lost and afterwards it may take some time to find the network again. So he went to a local store of a German provider (T-Mobile) and asked. They told him “Sure, disable G3 and it will work” (G3 means UMTS connection).

Went through the internet and found some articles which seem to approve this issue. Looks like that nobody is perfect. After checking the settings of my iPhone I’ve recognized that I’ve disabled G3 in order save battery run time. This would explain why I’ve not experienced such problems. At least it sounds reasonable, doesn’t it?

Give us back good old analogue telephones with cable! Just kidding of course. If you experience similar problems feel free to post them here.

A few related links I found regarding this issue:

Howto Beautify Ugly .PHP URL’s

January 17th, 2009 Category: Apache, PHP/MySQL

You probably know this ugly .PHP links with many parameters like

http://technitip.net/test.php?param1=p1&param2=p2&param3=p3


I really don’t like this look. Doesn’t the following URL look much better?

http://technitip.net/test/p1/p2/p3


I think yes. So here is tutorial how you can beautify your links using Apache and mod_rewrite.

The Test Script

We assume that mod_rewrite is loaded in your Apache config and generate a simple PHP script called “test.php”:

<?php
echo "Parameter 1: " . $_REQUEST['param1'] . "<br />";
echo "Parameter 2: " . $_REQUEST['param2'] . "<br />";
echo "Parameter 3: " . $_REQUEST['param3'] . "<br />";
?>

This script gets the parameters param1, param2, etc. which have been given to the PHP page and prints them out. To check it we put the URL into the browser:

http://technitip.net/test.php?param1=p1&param2=p2&param3=p3

And get the result:

Parameter 1: p1
Parameter 2: p2
Parameter 3: p3

Simple Rewrite

Fine, passing parameters to our PHP script is working but still looking ugly. Now we generate a .htaccess file in the root directory of your web directory:

RewriteEngine On
RewriteBase /
RewriteRule ^(test)/?(.*)$ test.php [L,QSA,NC]

What will happen? test.php will be redirected to test and all parameters will be parsed like before, we can test it:

http://technitip.net/test?param1=p1&param2=p2&param3=p3&param4=p4

First Parameter Rewrite

Nice, but not yet what we really want. So we put another line into the .htaccess (before our first RewriteRule, not after! It’s important):

RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2 [L,QSA,NC]
RewriteRule ^(test)/?(.*)$ test.php [L,QSA,NC]

For every parameter we need a new expression /([a-z0-9]+)(/[^/]+)?/

This will convert the line /test/p1 into test.php?param1=p1. Note that only the characters a-z und 0-9 are allowed as parameters. For the first parameter $2 is used.

Second Parameter

We repeat this step for every further parameter we need to hand over, $4 is used for the second parameter (not $3!):

RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2&param2=$4 [L,QSA,NC]
RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2 [L,QSA,NC]
RewriteRule ^(test)/?(.*)$ test.php [L,QSA,NC]

Three Parameters

Or with 3 parameters. Note: Since the .htaccess is parsed from top to bottom the rewrite rule with the highest number of parameters must be located at the top of the .htaccess. $6 is used for the third parameter!

RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/([a-z0-9]+)(/[^/]+)?/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2&param2=$4&param3=$6 [L,QSA,NC]
RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2&param2=$4 [L,QSA,NC]
RewriteRule ^(test)/([a-z0-9]+)(/[^/]+)?/?(.*)$ test.php?param1=$2 [L,QSA,NC]
RewriteRule ^(test)/?(.*)$ test.php [L,QSA,NC]

We test again with 3 parameters:

http://technitip.net/test/p1/p2/p3


Parameter 1: p1
Parameter 2: p2
Parameter 3: p3

Looks better, indeed.

Hint

Be sure you have enabled “Options FollowSymLinks” or Options “SymLinksIfOwnerMatch” in your Apache or virtual host config. Otherwise mod rewrite will not work!

Domain Redirects

January 16th, 2009 Category: Apache

Avoid Double Content

There are two reasons to redirect e.g. mydomain1.de to www.mydomain1.de:

  1. It avoids detecting search machines “double content”
  2. I personally prefer having one unique URL for a homepage, also if a user enters mydomain1.de he will be redirected to www.mydomain1.de
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^mydomain\.de$ [NC]
RewriteRule ^(.*) http://www.mydomain.de/$1 [L,R=301]

The redirect is defined as 301 “permanent”. Please note that these rewrite settings only work if the correct setting for “AllowOverride” is done within the Apache settings of your host or virtual host configuration.

Redirect Domain to another Domain

If you want to redirect a complete domain, here mydomain1.de including subdomains to another domain e.g. mydomain2.de put the following code into the .htaccess of the web root directory of mydomain1.de:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)mydomain1\.de$
RewriteRule ^(.*)$ http://www.mydomain2.de/$1 [R=301,L,NC]

Using this rewrite condition all hosts *.mydomain1.de including mydomain1.de will be redirected to www.mydomain2.de. Everything behind .de/ will be kept.

Furthermore the redirect is defined as 301 which means permanent redirect. This will avoid that search machines like Goole will treat you with “double content”.

Hint

Be sure you have enabled “Options FollowSymLinks” or Options “SymLinksIfOwnerMatch” in your Apache or virtual host config. Otherwise mod rewrite will not work!

Working with Apache/2.2.3

MySQL Performance Tips

January 11th, 2009 Category: PHP/MySQL

Optimizing a MySQL server is probably not very easy. It depends on your database structure, how many users are accessing your server and so on.

Basics

But there are a few things which could help to improve your performance. On my configuration I’ve added skip-name-resolve in my.cnf:

[mysqld]
skip-name-resolve

Now the MySQL server will not do any DNS name resolves. Please note that permissions based on hostnames will no longer work!

For security reasons I would also recommend binding only to the localhost address. Using this the MySQL server is not reachable on the Ethernet interface. In earlier version of MySQL this was usually done with the skip-networking parameter.

[mysqld]
bind-address    = 127.0.0.1

And I’ve added skip-external-locking and skip-locking:

[mysqld]

skip-external-locking
skip-locking

This could also improve your performance.

Search Length

For text search queries with a allowed length of 2 characters add this line:

ft_min_word_len="2"

Otherwise default minimum length is 3 characters, which means that a search query “select * like ‘%AB%’” will never return any data.

Cache Settings

Caching seems to be a very important thing when optimizing your server. My feeling is that the standard configuration of a MySQL server is not really designed for machines with 1 GByte memory or above.

Below is my configuration, with a few cache settings increased.

[mysqld]
query_cache_limit    =  1M
query_cache_size     = 32M
thread_cache_size    =  8
join_buffer          =  1M
table_cache          = 16M
sort_buffer_size     =  2M
read_buffer_size     =  2M
read_rnd_buffer_size =  2M
tmp_table_size       = 48M
max_allowed_packet   = 16M
thread_stack         = 128K
key_buffer_size      = 32M

This configuration works on a machine with 1 GByte RAM and several databases running. Basically I recommend to increase the cache size settings. And memory helps almost always.

Applies to MySQL version: 5.0.32

Network Bandwidth Performance Measurement with Iperf

January 10th, 2009 Category: Linux

Another easy to use tool for measuring the network bandwidth is Iperf. On Debian it can be installed using:

apt-get install iperf

Optionally the source or the Windows binary is available from sourceforge.net/projects/iperf

Building and installing from source is done using a few commands:

tar xvfz iperf-2.0.4.tar.gz
cd iperf-2.0.4
./configure
make
make install

Once installed iperf the server is started on machine 1:

machine1:~# iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------

Next the client is started on machine 2:

machine2:~# iperf -c machine1.mydomain.de
------------------------------------------------------------
Client connecting to machine1.mydomain.de, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[  3] local xx.xx.xx.xx port 45325 connected with yy.yy.yy.yyport 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  96.6 MBytes  80.9 Mbits/sec

Tested on two servers connected with 100 MBit/s located at two different providers in Germany we get a result of 80.9 MBits/sec.

This result is slightly higher compared to the result from our measurement done with NETIO in the article Network Throughput Measurement. So we start the test again with addtional parameters:

machine2:~# iperf -c machine1.mydomain.de -w 512k -l 512k
------------------------------------------------------------
Client connecting to machine1.mydomain.de, TCP port 5001
TCP window size:   256 KByte (WARNING: requested   512 KByte)
------------------------------------------------------------
[  3] local xx.xx.xx.xx port 40987 connected with yy.yy.yy.yyport 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  72.0 MBytes  60.3 Mbits/sec

Now using modified read/write buffer size and TCP windows size we get almost the same result as in our test with netio.

Definitely a tool which can be recommended to check your network throughput!