# PHP performance

## xankra

Hi! I have recently installed gentoo on a web server, a dual pentium pro@200mhz with 72 MB RAM. It has apache2, PHP 5 and I installed a vBulletin forum (the MySQL server is on another machine). When it comes to serve static html pages, it is lightning fast. However, when browsing the forum it takes moreless 11 seconds to show the new page... what puzzles me is that, using top while browsing, neither the CPUs nor the memory run out (I mean, neither CPU go above 50% and there is allways 15 megs of ram availiable).

The only configuration I made was changing the amount of reserved memory for php scripts from 128 megas to 20 and then to 10. Is there some other tweaking I could make to improve the performance? Does it need more RAM, despite the fact of allways having free, unused 15 megs?

Thanks in advance!

----------

## blu3bird

emerge one of these and restart apache.

```
* dev-php5/pecl-apc

     Available versions:  3.0.12_p2 3.0.13

     Homepage:            http://pecl.php.net/APC

     Description:         A free, open, and robust framework for caching and optimizing PHP code.

* dev-php5/xcache

     Available versions:  1.2.0

     Homepage:            http://trac.lighttpd.net/xcache/

     Description:         Another PHP opcode cache and encoder.

* dev-php5/eaccelerator

     Available versions:  0.9.5

     Homepage:            http://www.eaccelerator.net/

     Description:         A PHP Accelerator & Encoder.
```

----------

## Janne Pikkarainen

Frankly I don't think in this case any opcode-cache can help. This can't be about a real performance problem, instead there is something rotten in the setup. My first guess is that the php script is making a some kind of lookup (a dns lookup, perhaps?), which fails after timeout. During waiting ... well ... everything just gets stalled.

----------

## astor84

I swear by dev-php5/eaccelerator. However, I think that the post above mine certainly asks a good question. I actually had a very similar issue caused by the MySQL server requiring the MySQL client's hostname to resolve before it would allow the connection to happen. It was taking forever for the DNS queries to resolve and it caused a similar issue (10-15 second response times).

Try disabling this by adding the following line in the [mysqld] section of /etc/mysql/my.cnf and then restarting MySQL:

```
skip-name-resolve
```

... OR ... 

Add the hostname of the mysql client to /etc/hosts on the box running MySQL. This will greatly shorten the amount of time required to look-up the ip address for the hostname.

I prefer the latter solution.

----------

## liber!

I would strongly advise xcache!

Also disable as much modules/use flags as you can from apache and php.

You could also try a more lightweigth webserver like lighttpd (xcache is from the same people).

l!

----------

## m4rl0n

 *liber! wrote:*   

> I would strongly advise xcache!
> 
> l!

 

To xcache work properly on Gentoo I need to do this:

```

nano -w /etc/php/cgi-php5/ext/xcache.ini

```

comment line zend_extension = .....

;zend_extension = /usr/lib/php5/lib/php/extensions/debug-non-zts-20050922/xcache.so

an include a new one:

extension=xcache.so

xcache.ini:

```

;zend_extension = /usr/lib/php5/lib/php/extensions/debug-non-zts-20050922/xcache.so

extension=xcache.so

; Change xcache.admin.user to your preferred login name

xcache.admin.user   = "marlon"

; Change xcache.admin.pass to the MD5 fingerprint of your password

; Use md5 -s "your_secret_password" to find the fingerprint

xcache.admin.pass   = "xxxxxxxxxxxxxx"

auto_globals_jit = "0"

xcache.cacher = "1"

xcache.size = "10M"

xcache.count = "2"

xcache.slots = "8k"

xcache.var_size = "0"

xcache.var_count = "1"

xcache.readonly_protection = "0"

xcache.mmap_path = "/dev/zero"

xcache.stat = "1"

xcache.optimizer = "0"

xcache.coverager = "0"

xcache.coveragedump_directory = ""

```

best regards,

Marlon

----------

## stelardactek

I'm having a similar issue, except only with mediawiki. Every other web application (phpMyAdmin, a modified PHPBB) works fast, and mediawiki USED to work fast too. Not so long a go it stopped working quickly, and I can't figure out what is wrong. Any ideas?

----------

## kashani

stelardactek,

It might be Innodb related since Mediawiki does use Innodb tables and I don't think any of those other packages use them. Mysql has separate buffers for Innodb and Myisam tables. By default the buffers are pretty small in Gentoo. 

I'd add these lines to you /etc/mysql/my.cnf and restart Mysql. Then you can see an queries that run longer than 1 second which might point you in the right direction. 

```

#LOGGING =======================================================

log-slow-queries                = /var/log/mysql/slow-query.log

long_query_time                 = 1 

```

kashani

----------

## stelardactek

Thanks kashani, but this doesn't seem to be the problem. MediaWiki is still running very slow, but nothing has appeared in this slow queries log file.

I have already tried various PHP opcode cachers, disabled reverse lookup for mysql, disabled logging for apache. I'm not sure what else to try.

----------

## kashani

I'd try turning on PHP error logging next. In the vhost conf for mediawiki add something like this:

```

php_value log_errors On

php_value error_log "/var/log/apache2/mediawiki.log"

```

With luck that might tell you something useful.

kashani

----------

## stelardactek

I'm afraid this didn't yeild any results either. The log file was never even generated.

----------

