Jump to content


Photo

PHP APC Help

apc php php apc

  • Please log in to reply
7 replies to this topic

#1 pascal_22

pascal_22

    Advanced Member

  • Members
  • PipPipPip
  • 151 posts

Posted 23 January 2013 - 02:13 PM

Hello,

I own a chat on my server. Sometimes when there are a lot of peaple, my whole website become slow and make user leave :(

So, my provider (i have a linux server) talk to me about PHP APC, that will be a good idea to increase the performance with caching

I search on the web, but i still have some question!
What should i cache with APC? Query string, vars......
Not that my query string are 95% dynamic....? It's that good for that...?

For my chat, i use short polling(ajax/json query send every 2 or 3 seconde)... but now i switch to long polling in a while loop. My long polling isn't yet online, it's on my dev server!


Thank for giving to me where should i start with APC!

Thanks a lot

PAscal

#2 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,040 posts
  • LocationWA

Posted 23 January 2013 - 02:24 PM

Without you having to do anything at all (besides install APC) your PHP code will be cached. That means PHP doesn't have to read from the hard drive every time it tries to execute a file. Hard drives are slow.

Turn on APC and see if that improves performance enough. If not then you can revisit the issue of caching.

#3 pascal_22

pascal_22

    Advanced Member

  • Members
  • PipPipPip
  • 151 posts

Posted 23 January 2013 - 02:39 PM

thanks for the reply!
The admin of my server told me that apc is already installed!!!

I can start using it now!!!

So any hint for me?

thank!

Pascal

#4 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,040 posts
  • LocationWA

Posted 23 January 2013 - 03:38 PM

You don't have to do anything to start using it. It works automatically.

But if you already have it installed then the file caching alone isn't enough. What does your code look like? You can probably store some information in APC to spare the database some queries.

#5 pascal_22

pascal_22

    Advanced Member

  • Members
  • PipPipPip
  • 151 posts

Posted 24 January 2013 - 10:43 AM

Hi thanks for the reply.

For now i have my script php and my script JS and Ajax. So depending on the action made by the user, ajax call my php page and return the good thing. As i say, i use long polling, so a while loop on the server who check for new message to show on the chat. so when i find a new message, the while loop stop and return the new message(s) to the chat and show it.

I want to speed thing because when there are a lot of user, the chat makes whole site slow....

But with APC, i don't know what cache in it? do i should cache dynamic query, uservariable.....other...

that why a asked some help!

Thanks!

#6 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 24 January 2013 - 12:15 PM

Does this chat system use PHP sessions, a database, or any other third party system? Also, what kind of responses does it send to the clients?
There are a myriad of concerns when creating an AJAX-based chat system, especially when you start to get a lot of users. Most of which requires intimate knowledge about the way all systems involved function, potential bottlenecks, optimization tweaks, and (most importantly) being able to properly profile your code.

I've made an AJAX-based chat system which supported a few hundred users. I had to tweak everything including the PHP session handler (or rather circumvent it completely, to maintain the responsiveness and keep the system resource utilization to a minimum.

You should perhaps also consider hiring someone who knows what they're doing, if this is a project which is either commercial (in other words, making you money), or if don't have a few weeks to get to grips with everything.

As for how to use and configure APC, I recommend reading the PHP manual page. Though, as Requinix already pointed out, you shouldn't have to do anything to use it.
When it comes to what it caches... That's a whole different question, and one which would take a lot of time to explain properly. Thus I recommend a search for "opcode cache" on Wikipedia, or similar, and read about how they work in general. After you've done that, the PHP manual should give you the necessary details for that particular implementation.

Edited by Christian F., 24 January 2013 - 12:19 PM.

Keeping it simple.

#7 pascal_22

pascal_22

    Advanced Member

  • Members
  • PipPipPip
  • 151 posts

Posted 28 January 2013 - 09:25 AM

Hello Christian!

This chat use a bit vars sessions only to check if a private msg need to be shown or not. because on my chat, we can send private msg. so i check if the receipient is the current member, if yes i show the private msg.

I tried a bit to work with APC last friday. I've made a simple test. Look:
$bar = 'BAR';
apc_store('foo', $bar);
echo apc_fetch('foo');

At first, it work very well BUt, if a make some refresh page... 50% of the times it show notting(empty vars)... and 50% show "BAR"
if i did apc_exists... some it exist and sometimes not!

So i asked why to the admin of my server (i'm on a VPS server).
It is short answer was:
APC use shared memory between same process of same tree... so you have to fetch to see if your apc vars is empty or not.......
man... he told me only that!!
So i'm totally lost! is that normal that sometime it fetch an empty string and sometime not.....
Thanks for your help!
Pascal

#8 pascal_22

pascal_22

    Advanced Member

  • Members
  • PipPipPip
  • 151 posts

Posted 30 January 2013 - 08:45 AM

Is that normal?

thanks!

Edited by pascal_22, 30 January 2013 - 08:45 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com