Jump to content


Corporate Sponsors


Latest News: (loading..)

- - - - -

Realpath cache optimisation ( PHP 5.3.2+ )


2 replies to this topic

#1 FWR Media

  • Community Member
  • 6,463 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 01 April 2011, 11:14

( PHP 5 >= 5.3.2 )

I am currently working on some projects using Zend Framework which is an excellent but huge framework.

One of the problems of systems like this is the huge number of files that are included ( e.g. using include_once etc. ). It is not only Zend Framework that suffers speed issues due to this but all systems which include a fair number of files, any of the frameworks, Drupal etc. etc.

The PHP realpath cache helps greatly here except for one thing, as standard PHP ( php.ini ) sets realpath_cache_size at a miserly 16K which is ridiculously small.

realpath_cache_ttl is set to 120 seconds which also may or may not benefit by being larger dependent on the system.

I ran a test on the system I am building and saw the following on first page load: -

  • Parse time: 0.1278 seconds
  • Realpath cache used: 16.35K ( standard PHP 16k )
  • Realpath cache remaining: -0.35K

I then adjusted to realpath_cache_size = 150k and saw: -

  • Parse time: 0.0521 seconds
  • Realpath cache used: 92.61K ( adjusted to 150k )
  • Realpath cache remaining: 57.39K

Such a simple change with such dramatic improvements, I though it worth sharing.

In case it helps below is a simple method I use in my system class: -

    public function getSystemData( $target = false ) {
      $realpath_cache_available = (int)str_ireplace( 'k', '', ini_get( 'realpath_cache_size' ) );
      $realpath_cache_used = number_format( ( realpath_cache_size() / 1000 ), 2 );
      switch ( $target ) {
        case 'parse_time':
          return number_format ( ( microtime ( true ) - self::$system_time ), 4 );
          break;
        case 'realpath_cache_used':
          return $realpath_cache_used . 'K';
          break;
        case 'realpath_cache_remaining':
          return ( $realpath_cache_available - $realpath_cache_used ) . 'K';
          break;
        default:
          return 'data unavailable';
          break;
      }
    } // end method

self::$system_time is set when the system bootstraps using microtime( true );
Ultimate SEO Urls 5 PRO - Multi Language Modern, Powerful SEO Urls

KissMT Dynamic SEO Meta & Canonical Header Tags

KissER Error Handling and Debugging

If you found my post useful please click the green + sign to the right

Please only PM me for paid work.


#2 Waddy

  • Community Member
  • 1 posts
  • Real Name:John

Posted 19 April 2011, 11:22

Thats a great tweak, thanks for sharing, just been reading about it, its a great tip. I am using shared hosting php 5.3 and oscommerce v3, we are allowed to use custom php.ini, if I do it at php.ini level the function you provide is not required in the scripts or?

My host supports eaccelerator and i will have to ask them if this is part of eaccelerator.

Edited by Waddy, 19 April 2011, 11:22.


#3 FWR Media

  • Community Member
  • 6,463 posts
  • Real Name:Robert Fisher
  • Gender:Male
  • Location:Stowmarket - Suffolk - UK

Posted 19 April 2011, 12:23

View PostWaddy, on 19 April 2011, 11:22, said:

Thats a great tweak, thanks for sharing, just been reading about it, its a great tip. I am using shared hosting php 5.3 and oscommerce v3, we are allowed to use custom php.ini, if I do it at php.ini level the function you provide is not required in the scripts or?

My host supports eaccelerator and i will have to ask them if this is part of eaccelerator.

eAccelerator is an opcode cache it has nothing to do with the realpath_cache.

The script does nothing except report the used vs available of the realpath_cache.

Basically if the realpath_cache is being used up then it probably is not offering full benefit .. ideally the size should be set at the lowest level at which it is nearly .. but not quite, used up.
Ultimate SEO Urls 5 PRO - Multi Language Modern, Powerful SEO Urls

KissMT Dynamic SEO Meta & Canonical Header Tags

KissER Error Handling and Debugging

If you found my post useful please click the green + sign to the right

Please only PM me for paid work.