DayCoder Posted September 22, 2010 Share Posted September 22, 2010 Hi, I run a top site which has incentives. Originally when a voter came and voted, the script in the background would run file() but I noticed that it sometimes lagged and caused the voter to wait a few secs before the page loads. I was then told by a developer to use file_get_contents(), but I was getting the same results. It occasionally lagged, even on my own websites that are voting on it. I decided to log the incentives now, and get a cron to check and process any incentives instead of the user lagging, but now it's starting to kill my server as you can see below xxxxx.com 1.05 0.49 0.1 Top Process %CPU 77.2 php -q process_incentives.php Top Process %CPU 24.0 php -q process_incentives.php Top Process %CPU 8.0 php -q timers/5mins.php xxxxx.com 0.99 0.13 0.0 Top Process %CPU 9.0 php -q timers/30mins.php Top Process %CPU 7.0 php -q timers/5mins.php Code in process_incentives.php //REWARD VOTERS $get = mysql_query("SELECT id,url FROM incentives ORDER BY id DESC limit 50;"); while ($game = mysql_fetch_array($get)){ file_get_contents("$game[url]"); mysql_query("DELETE from incentives WHERE id='$game[id]'"); } Quote Link to comment https://forums.phpfreaks.com/topic/214143-using-file_get_contents-for-vote-incentives/ Share on other sites More sharing options...
Psycho Posted September 22, 2010 Share Posted September 22, 2010 Unless you are leaving out code that file_get_contents() serves no purpose. If you are using that content somewhere is there some reason you can't store the contents in the database to begin with? Quote Link to comment https://forums.phpfreaks.com/topic/214143-using-file_get_contents-for-vote-incentives/#findComment-1114292 Share on other sites More sharing options...
DayCoder Posted September 22, 2010 Author Share Posted September 22, 2010 Yea, I'm not trying to get any content. I'm just trying to hit reward files, that webmasters set on their own servers to reward their voters when they vote. Top site, websites come and submit their website. They sometimes set a reward file in their account on my topsite, for my server to hit, when they send a voter over to vote. if($vote){ $ip = $_SERVER['REMOTE_ADDR']; if(!fetch("SELECT id FROM $tab[vote] WHERE game='$id' AND ip='$ip';")){ mysql_query("INSERT INTO $tab[vote] (game,ip) VALUES ('$id','$ip');"); mysql_query("UPDATE $tab[game] SET votes=votes+1, totalvotes=totalvotes+1 WHERE id='$id';"); if(($game[rewardscript]) && (!$no)){ mysql_query("INSERT INTO incentives (url) VALUES ('$game[rewardscript]$REQUEST_URI');"); } } elseif(($game['alwaysreward'] == 1) && ($game['rewardscript']) && (!$no)){ mysql_query("INSERT INTO incentives (url) VALUES ('$game[rewardscript]$REQUEST_URI');"); } header("Location: vote.php?id=$id&voted=1"); } Quote Link to comment https://forums.phpfreaks.com/topic/214143-using-file_get_contents-for-vote-incentives/#findComment-1114297 Share on other sites More sharing options...
DayCoder Posted September 22, 2010 Author Share Posted September 22, 2010 On the code above, where it "INSERTS INTO incentives" is where file_get_contents() use to be. Quote Link to comment https://forums.phpfreaks.com/topic/214143-using-file_get_contents-for-vote-incentives/#findComment-1114299 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.