Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/273554-php-apc-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/273554-php-apc-help/#findComment-1407773
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/273554-php-apc-help/#findComment-1407787
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/273554-php-apc-help/#findComment-1407942
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/273554-php-apc-help/#findComment-1407969
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/273554-php-apc-help/#findComment-1408761
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.