update automatically
Moderator: General Moderators
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
update automatically
well im on the last stages of my stat sig...ive managed to build a script to pull the information from a site, store it in a database, and have the data displayed on a sig...the one last step i need to conquer is how to make the database update automatically....right now when ever i want to update the stats on the sig i have to manually go to a specific link type in the pin# and once that is done i hit update and it updates the database with the new information...
My question is how can i make it update automatically...lets say on an hourly basis.....with out me actually having to type in the pin#
so can someone provde me with some logic as to how to do this and maybe some functions i can look into?
thanks
My question is how can i make it update automatically...lets say on an hourly basis.....with out me actually having to type in the pin#
so can someone provde me with some logic as to how to do this and maybe some functions i can look into?
thanks
you need to pull the info from the other site automatically - says every hour - by using crontab (on linux) or tasks schedule on windows. This will execute your script every one hour; and your script will update the info by getting the info from the other site. If you still need to enter the pin, why not add that pin to the script itself?
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
ok well im working on combinding the script so it is one file rather then three different files.
ive managed to get it to two files...the index.php and the stats.php but i need a little help combinding the index and stats.php together.... right now here is my index file
which is a simple form that submits the pid to stats.php
and currentley my stats.php looks like this
what my goal to do is....i just want to be able to point to stats.php and it will take the URL get the contents of it and display it all in one shot....but when i change
to
it dosnt work....it seems to only work when the form posts the information...i was thinking of maybe making the forum submit automatically...but i would like to keep it to 1 file and i try to avoide java stuff.... any ideas?
ive managed to get it to two files...the index.php and the stats.php but i need a little help combinding the index and stats.php together.... right now here is my index file
Code: Select all
<?php
///////////////////////////////////////////
echo "e;<form method = 'post' action = 'stats.php'>
<input type = 'text' name = 'pid' value = '40478458384'>
<input type = 'submit'>"e;;
///////////////////////////////////////////
?>and currentley my stats.php looks like this
Code: Select all
<?php
$url = "e;https://www.novaworld.com/Players/DfxStats.aspx?id="e;. $_POSTї'pid'] ."e;&p=766075"e;;
//Gets the content of the submited URL
$content = file_get_contents($url);
echo $content;
?>Code: Select all
$url = "e;https://www.novaworld.com/Players/DfxStats.aspx?id="e;. $_POSTї'pid'] ."e;&p=766075"e;;Code: Select all
$url = "e;https://www.novaworld.com/Players/DfxStats.aspx?id=40478458384&p=766075"e;;-
php_wiz_kid
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 24, 2003 7:33 pm
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Well, php_wiz_kid, you're asking a different question. I'll answer SidewinderX's first.
What you are messing up is the GET and POST variables. Your script is expecting a POST variable, but when you put a variable into the URL, it's a GET variable. Solution? Translate everything to "GET"s.
As for making PHP do this without cron, sorry man, that's not possible.
What you are messing up is the GET and POST variables. Your script is expecting a POST variable, but when you put a variable into the URL, it's a GET variable. Solution? Translate everything to "GET"s.
As for making PHP do this without cron, sorry man, that's not possible.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Or store in your database the next "interval" of time which your data should be updated.
So lets say I access the page, and havn't done so in 30 min. In my code I want the data to be updated every hour.
So in my database I am storing the a) current time, b) next update.
Once the current time has surpased the next update, increment the next update, and update the current time upon each page request.
Or you can just have the data update itself on each page call.. booo.
Ultimate solution? Use cron.
So lets say I access the page, and havn't done so in 30 min. In my code I want the data to be updated every hour.
So in my database I am storing the a) current time, b) next update.
Once the current time has surpased the next update, increment the next update, and update the current time upon each page request.
Or you can just have the data update itself on each page call.. booo.
Ultimate solution? Use cron.
-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
well i kind of forgot about this topic on purpose as i was clueless at what had to be done. but now that i am a little more learned about what i need to do i would like to revisit the topic and conquer it once and for all.
First I would like to start off by saying that my friend created a pthon script to do this for me, however my host is running python 2.2 and its programed for 2.4. Also i would like it to be done in php as everything else in my script is done in php.
Also i have compiled everything into one script that uses _GET to make it easier to deal with.
My first idea was to write a script like this
And create 24 if statements and each time it was on the hour it would submit a URL for example http://stats.extreme-hq.com/update.php&pid=123456789
However would it be possable to submit the URL with out the browser executing it?
Also I havnt looked into cron, but if my assumption that the above script will not work i will probabley come down from my high horse and use a cron job. In which case I would need a little explination on what i need to do/how it would work.
First I would like to start off by saying that my friend created a pthon script to do this for me, however my host is running python 2.2 and its programed for 2.4. Also i would like it to be done in php as everything else in my script is done in php.
Also i have compiled everything into one script that uses _GET to make it easier to deal with.
My first idea was to write a script like this
Code: Select all
<?php
$time = date("h:i",time());
echo "<br>";
if ($time == '09:00') {
//update
}
elseif ($time == '10:00') {
//update
}
else {
//dont update
}
?>However would it be possable to submit the URL with out the browser executing it?
Also I havnt looked into cron, but if my assumption that the above script will not work i will probabley come down from my high horse and use a cron job. In which case I would need a little explination on what i need to do/how it would work.
I would use a cron job for this. I feel this is the easiest and best solution. On inspection of your website, http://www.extreme-hq.com, I found that you do have cPanel installed. You may use cPanel to schedule a cron job to run every hour, or whatever amount of time you choose. Go into cPanel, click the Cron Jobs link. On the next page, click standard. Enter the address of the php file you want to run and the time(s).
With cron jobs you do not need the php script to do anything with if statements deciding if it is time to run it. When it comes time the cron job will execute the script. You actually do not need to use _GET at all. If the variable does not change you might as well embed it into the code, unless there is a security issue if someone found the script. That doesn't seem to be the case since you have publicly posted the pin number in the script in a previous message here. I would do something like:
And if that is the script you want to run every hour, do so with the cron job. I think you are probably using regex to get the content from the page so then you could take those stats and save them to a database. When your image loads it will take the stats from the database.
Is this what you are looking to do? I've been working with php for about two years now. I can't call myself a php expert at all; I am a beginner myself at the age of fourteen, but I hope I was helpful.
With cron jobs you do not need the php script to do anything with if statements deciding if it is time to run it. When it comes time the cron job will execute the script. You actually do not need to use _GET at all. If the variable does not change you might as well embed it into the code, unless there is a security issue if someone found the script. That doesn't seem to be the case since you have publicly posted the pin number in the script in a previous message here. I would do something like:
Code: Select all
<?php
$url = "https://www.novaworld.com/Players/DfxStats.aspx?id=40478458384&p=766075";
//Gets the content of the submited URL
$content = file_get_contents($url);
echo $content;
?>Is this what you are looking to do? I've been working with php for about two years now. I can't call myself a php expert at all; I am a beginner myself at the age of fourteen, but I hope I was helpful.