Changeset 1164 for trunk/common


Ignore:
Timestamp:
01/14/12 16:18:10 (4 months ago)
Author:
bogdan2412
Message:

Make infoarena compatible with HPHP.

  • Implemented APC caching support since eaccelerator is not compatible with HPHP and although we support memcached, we do not use it on live.
  • Replaced instances of create_function_cached with php anonymous functions. This bumps the PHP version requirement to 5.3, but it allows the code to work with HPHP, since dynamic function generation is replaced with staticly analyzable functions. This also removes a horrible, terrible hack in Textile.php which was storing the current instance of the Textile class being processed as a static variable so that it could be accessed by anonymous functions.
  • Replaced occurrences of assert with log_assert.
  • When running under HPHP, IA_HPHP_ENV is defined and is used to bypass some incompatible code (redundant ini configuration checks).
  • Fixed some includes that were dependent on the working directory being www/
  • Included a sample HPHP configuration file and a Makefile with compilation commands.

REVIEW URL: http://reviewboard.infoarena.ro/r/182/

Location:
trunk/common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/cache.php

    r966 r1164  
    144144//      mem_cache_purge deletes everything from the cache. Try to avoid calling it. 
    145145// 
    146 // FIXME: cache is not logged. See IA_LOG_MEM_CACHE. 
    147146if (IA_MEM_CACHE_METHOD == 'none') { 
    148147 
     
    259258        } 
    260259    } 
     260 
     261} else if (IA_MEM_CACHE_METHOD == 'apc') { 
     262    // APC cache implementation 
     263    function mem_cache_get($cache_id) { 
     264        $res = apc_fetch($cache_id); 
     265        if ($res === false) { 
     266            if (IA_LOG_MEM_CACHE) { 
     267                log_print("MEM CACHE: miss on $cache_id"); 
     268            } 
     269            return false; 
     270        } else { 
     271            if (IA_LOG_MEM_CACHE) { 
     272                log_print("MEM CACHE: hit on $cache_id"); 
     273            } 
     274            return unserialize($res); 
     275        } 
     276    } 
     277 
     278    function mem_cache_set($cache_id, $object, $ttl = IA_MEM_CACHE_EXPIRATION) { 
     279        log_assert($object !== 'false', "Can't cache false values"); 
     280        apc_store($cache_id, serialize($object), $ttl); 
     281 
     282        if (IA_LOG_MEM_CACHE) { 
     283            log_print("MEM CACHE: store $cache_id"); 
     284        } 
     285        return $object; 
     286    } 
     287 
     288    function mem_cache_delete($cache_id) { 
     289        apc_delete($cache_id); 
     290        if (IA_LOG_MEM_CACHE) { 
     291            log_print("MEM CACHE: delete $cache_id"); 
     292        } 
     293    } 
     294 
     295    function mem_cache_purge() { 
     296        if (IA_LOG_MEM_CACHE) { 
     297            log_print("MEM CACHE: purge"); 
     298        } 
     299        apc_clear_cache(); 
     300    } 
    261301} 
    262302 
  • trunk/common/common.php

    r1163 r1164  
    332332 
    333333    // Check for retarded php.ini settings. 
    334     if (IA_HTTP_ENV) { 
     334    if (IA_HTTP_ENV && !defined('IA_HPHP_ENV')) { 
    335335        log_assert(!ini_get("session.auto_start"), 
    336336                   "Please disable session.auto_start. It kills babies!"); 
  • trunk/common/db/attachment.php

    r1145 r1164  
    151151// You may use % as a wildcard 
    152152function attachment_get_all($page, $name='%', $start = 0, $count = 99999999) { 
    153     assert(is_whole_number($start)); 
    154     assert(is_whole_number($count)); 
     153    log_assert(is_whole_number($start)); 
     154    log_assert(is_whole_number($count)); 
    155155    $query = sprintf("SELECT ia_file.*, ia_user.username, ia_user.full_name as user_fullname 
    156156                      FROM ia_file 
     
    165165// _count for the above. 
    166166function attachment_get_count($page, $name='%', $start = 0, $count = 99999999) { 
    167     assert(is_whole_number($start)); 
    168     assert(is_whole_number($count)); 
     167    log_assert(is_whole_number($start)); 
     168    log_assert(is_whole_number($count)); 
    169169    $query = sprintf("SELECT COUNT(*) 
    170170                      FROM ia_file 
     
    184184// FIXME: does this belong here? 
    185185function attachment_get_filepath($attach) { 
    186     assert(is_array($attach)); 
     186    log_assert(is_array($attach)); 
    187187    return IA_ROOT_DIR.'attach/'. 
    188188            strtolower(preg_replace('/[^a-z0-9\.\-_]/i', '_', $attach['page'])) . '_' . 
  • trunk/common/textblock.php

    r1098 r1164  
    152152function textblock_copy_replace($srcprefix, $dstprefix, $replace, $security, 
    153153        $user_id, $remote_ip_info = null) { 
    154     assert($srcprefix != $dstprefix); 
    155     assert($security === null || is_textblock_security_descriptor($security)); 
    156     assert(is_whole_number($user_id)); 
     154    log_assert($srcprefix != $dstprefix); 
     155    log_assert($security === null || 
     156               is_textblock_security_descriptor($security)); 
     157    log_assert(is_whole_number($user_id)); 
    157158 
    158159    $textblocks = textblock_get_by_prefix($srcprefix, true, false); 
Note: See TracChangeset for help on using the changeset viewer.