LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-18-2006, 11:06 PM   #1
ReMuSoMeGa
LQ Newbie
 
Registered: Jun 2006
Posts: 7

Rep: Reputation: 0
Exclamation PHP Script Issues (Reading Cookies)


Hi, On my site im trying to make a skin selector. The skin chooser saves your preference in a cookie.

here is my index.php
Code:
<?
include('loadskin.php');
include(''.$path.'index.php');
?>

loadskin.php reads your cookie, and determines what skin you wanted to use. It then loads
the filepath to the template file and saves it as $path.

loadskin.php
Code:
<?php
$sskin = $_COOKIE["serialdevilskin"];
switch ($sskin){
case 1:
$path = "global/clean_devil/";
break;
case 2:
$path = "global/serialsws/";
break;
if(($sskin <> 1) && ($skin <> 2)){
$sskin = "1";
}
}

The script works perfectly, it remembers what skin you chose, and it loads it correctly.
Now, here is the problem.

When ever I enable my new template system, my server loads go over 20 all of a sudden, and it crashes my server.

I am getting extremely high traffic, 30 queries a second, 70k unique hits daily. My server is getting a lot of traffic as it is, but my site uses a very well made search engine with 5 hour caching. Server loads are under 0.5 during peak hours.

Its obvious that the skin selector is causing the loads.

Can someone please help me fix this problem. Is there a better way to write this code without causing such a high load?

Thanks,
-Remus.
 
Old 06-19-2006, 07:07 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,415

Rep: Reputation: 99
i would place
if(($sskin <> 1) && ($skin <> 2)){
$sskin = "1";
}
before the switch. Now it is placed behind the last break - maybe this is causing an internal error.
Is there a typo in the 2nd comparison ?
 
Old 06-19-2006, 11:18 AM   #3
ReMuSoMeGa
LQ Newbie
 
Registered: Jun 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Yea, I just noticed that the IF statement was within the switch.

I moved it after, but I am still having the high server load issues.
 
Old 06-19-2006, 05:49 PM   #4
ReMuSoMeGa
LQ Newbie
 
Registered: Jun 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Well NVM, I solved the problem. I now store information in MySQL tables by IP instead - Works a lot faster than cookies.
 
Old 06-20-2006, 01:09 PM   #5
doc.nice
Member
 
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274

Rep: Reputation: 34
well, maybe works, but what for users having a dial up connection, thus getting a new IP whenever they connect to the internet (or DSL, at least in germany, many providers disconnect after 24 hours).

Normally, the php cookie code doesn't make such load problems, on my site it works without problems.
maybe your cookie SET-code is buggy?
if you can post it, I'll have a glance on it.

PS: why the empty string before $path in your include statement? include($path.'index.php') should be enough.
 
  


Reply

Tags
cookies, php, skin


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
issues with mirc script accessing our php script dtra Linux - Software 2 07-02-2005 04:30 PM
Reading cookies crazy diamond General 3 10-13-2004 11:12 AM
cookies in php RazorKnight Programming 1 10-08-2004 04:31 AM
PHP - Cookies, unserialize() dhbiker Programming 1 07-28-2004 02:18 PM
PHP and cookies. jacksmash Programming 13 04-02-2004 09:01 AM


All times are GMT -5. The time now is 12:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration