pascal_22 Posted January 23, 2013 Share Posted January 23, 2013 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted January 23, 2013 Share Posted January 23, 2013 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. Quote Link to comment Share on other sites More sharing options...
pascal_22 Posted January 23, 2013 Author Share Posted January 23, 2013 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted January 23, 2013 Share Posted January 23, 2013 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. Quote Link to comment Share on other sites More sharing options...
pascal_22 Posted January 24, 2013 Author Share Posted January 24, 2013 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! Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 24, 2013 Share Posted January 24, 2013 (edited) 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 January 24, 2013 by Christian F. Quote Link to comment Share on other sites More sharing options...
pascal_22 Posted January 28, 2013 Author Share Posted January 28, 2013 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 Quote Link to comment Share on other sites More sharing options...
pascal_22 Posted January 30, 2013 Author Share Posted January 30, 2013 (edited) Is that normal? thanks! Edited January 30, 2013 by pascal_22 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.