SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a question about APC

    I've installed APC but it only keeps cache for current process so it doesn't retrieve the data when i enter the page again.
    I've been trying to google it but there's too much information about it.
    can someone give me a simple explanation about why it doesn't work, how it should and how to make it work?

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    What do you mean with 'current process'?

    What TTL have you put on the caches?

    Can you post some code of what you're trying to do? That way we can see what might be going wrong.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don't put TTL in order to keep it in cache until i manually remove it, but i've also tried setting TTL and it still didn't work.
    there's no code to post because I am just trying to store a variable on one page using
    apc_store and it will output the right result when i apc_fetch within the same script.
    but after i reload the page, it's no longer in cache so
    apc_fetch returns an empty result.

  4. #4
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    <?php

    $count 
    apc_fetch('test_counter'$success);
    if(!
    $success) {
        
    $count 0;
    }

    $count++;

    apc_store('test_counter'$count);

    echo 
    "\$count is currently set to $count";

    ?>
    Can you try the script above? Save it as a PHP file and then access it through your browser. Press F5 a couple of times. Does $count increase at all? Or does it stay at 0?

    Also, how is your error_reporting level set?

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It returns '1' every time.
    I've already tested it a lot, APC functions do work, the problem is,
    it only save cache for current process, if i reload the page, the cache is cleared.

  6. #6
    SitePoint Guru r2d2's Avatar
    Join Date
    Dec 2003
    Location
    In my van, fool!
    Posts
    646
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you copy in here what is says about apc in your phpinfo()?

    Also, have you setup the apc.php info script? It should be in the apc archive you downloaded. Copy it to your Web server document root. Then, open it in a text editor and set the administrator password (you'll find it near the top of the script). What does this say about user cache entries?

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am hosted on a managed VPS so they installed it for me (it's managed so i rather let them install things i never did before)

    Here's the phpinfo


    and about apc.php, here's where it's located in the server, didn't really understand where do i have to put it.


    I copied it into my root website folder and changed the password but it still doesn't work.

  8. #8
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it won't let me edit, forgot about the second part of the first image

  9. #9
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    OK, this is kinda weird.

    Can you ask your host (maybe you already know) how PHP is installed? As a sapi module? Or through (fast-)CGI?

  10. #10
    SitePoint Guru r2d2's Avatar
    Join Date
    Dec 2003
    Location
    In my van, fool!
    Posts
    646
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elme View Post
    I copied it into my root website folder and changed the password but it still doesn't work.
    You should just be able to visit in your web browser, eg. http://www.myrootdomain.com/apc.php

    When you say `it doesn't work`, what happens when you visit it in your browser?

  11. #11
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Immerse, phpinfo says "Server API : CGI " if that helps.

    r2d2, the apc.php file works, but it didn't help solving the problem, setting the password only allows me to login that page.

  12. #12
    SitePoint Guru r2d2's Avatar
    Join Date
    Dec 2003
    Location
    In my van, fool!
    Posts
    646
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you login, what does it show in `User Cache Entries`? You would expect to see a list of the entries that you've added.

  13. #13
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nothing is added, you can see it here (user:apc pass:12345)
    APC INFO (server1.shavek.com) (109.73.167.74)
    and the code that Immerse posted over here
    http://shavek.com/test.php

  14. #14
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    OK, I don't know much about how CGI works, but isn't it so that every request spawns a new CGI 'process' which is terminated at the end of the request?

    In that case, I don't think APC makes much sense, as the process is killed at the end of the request, which also terminates the APC cache.

    When using APC is an Apache module, the APC cache is kept intact so long as the Apache process runs, meaning that data can be shared across requests.

    I did find this article which might help a bit, but it looks like a lot of work, and it's possibly very outdated: FastCGI with a PHP APC Opcode Cache | Brandon&#039;s Blog

    Lastly, I'm not sure about the workings of CGI, so it's quite possible that what I've just written above is total claptrap.

  15. #15
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Great post Alex, very interesting...
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  16. #16
    SitePoint Guru r2d2's Avatar
    Join Date
    Dec 2003
    Location
    In my van, fool!
    Posts
    646
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would seem to make sense that APC use in FastCGI would be very different to use in PHP as a module. Found this article (Why APC sucks (and should be pulled from PECL)) which is a bit older than your link Immerse, which suggests XCache might be more suitable for FastCGI use. A search on google for FastCGI and XCache shows lots re using Lighttpd and NGinX though, rather than Apache.

    Looking at your apc.php, you can see that it isn't working as intended at all - so in this case using APC will probably be slowing you down - i.e. extra time caching the opcodes, that will then be cleared.

    Is there a reason you're using CGI, not running PHP as a module? You have a VPS, so you don't need to worry about other users accessing your cache as on shared hosting?
    Last edited by r2d2; Aug 31, 2011 at 06:09. Reason: added APC

  17. #17
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by r2d2 View Post
    XCache might be more suitable for FastCGI use
    Or memcache, even. That's a totally separate bit of software that doesn't care how PHP accesses it.

  18. #18
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I'd certainly be leaning towards memcache (cached values as opposed to code) in this situation, good thread.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  19. #19
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've never dealt with installing PHP and everything associated with it on a linux server, that's why I let my host install it, sicne I wanted everything to be secure and configured properly and they installed it under CGI.

    My current application handles a big amount http requests and queries per second so to lighten the cpu usage, I'm looking to store some information in the cache.
    (also trying to convert the app to use socket.io instead of handling ajax requests each second, but that's already a different thing)

    after reading your responses I've been reading a bit about cgi/apache module and the differences about them, and it also made me figure that installing PHP under apache module will reduce my CPU usage when I'm using that much http requests.

    I'll keep reading about xcache/memcache with CGI and see if i should use one of those or reconfigure php to use apache module and stick with APC.

    thank you.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •