.Bat to run .php page !help!
Moderator: General Moderators
.Bat to run .php page !help!
Hi i need some help as i dont understand cron...
i need to make so that everytime the clock hits 00:30 or 01:00 (every 30 min) it will uppdate a datatable and add value into it. it will do this every 30 min. and ive been told to use Cron. I dont understand Cron that much so i cant make the "function" im after. plz help
-Thanks in advance
-Thomas
i need to make so that everytime the clock hits 00:30 or 01:00 (every 30 min) it will uppdate a datatable and add value into it. it will do this every 30 min. and ive been told to use Cron. I dont understand Cron that much so i cant make the "function" im after. plz help
-Thanks in advance
-Thomas
Last edited by Goofan on Tue Dec 01, 2009 12:30 pm, edited 1 time in total.
- Grizzzzzzzzzz
- Forum Contributor
- Posts: 125
- Joined: Wed Sep 02, 2009 8:51 am
Re: Cron!!
might be worth looking at forums dedicated to Cron
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Cron!!
Not really PHP because you don't need it here, but here is a solution that can use PHP.
You either edit /etc/crontab or create a crontab for a specific user by doing 'crontab -e'. Then add the following:
Then in /path/to/phpfile.php add the PHP/SQL to do the update.
To skip PHP (assuming you're using MySQL), just add the SQL to the crontab:
You either edit /etc/crontab or create a crontab for a specific user by doing 'crontab -e'. Then add the following:
Code: Select all
0,30 * * * * /path/to/php /path/to/phpfile.phpTo skip PHP (assuming you're using MySQL), just add the SQL to the crontab:
Code: Select all
0,30 * * * * mysql -h hostname -u username -ppassword -e "UPDATE mytable SET field = 'value' WHERE something = 'something'"mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Cron!!
this part:AbraCadaver wrote:Not really PHP because you don't need it here, but here is a solution that can use PHP.
You either edit /etc/crontab or create a crontab for a specific user by doing 'crontab -e'. Then add the following:Then in /path/to/phpfile.php add the PHP/SQL to do the update.Code: Select all
0,30 * * * * /path/to/php /path/to/phpfile.php
To skip PHP (assuming you're using MySQL), just add the SQL to the crontab:Code: Select all
0,30 * * * * mysql -h hostname -u username -ppassword -e "UPDATE mytable SET field = 'value' WHERE something = 'something'"
-h hostname -u username -p password
is it to connect to the database or something else?
Re: Cron!!
and if its the "connect to database shouldnt database.... be in there aswell...
exampel:
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "this"; <-------this as -n this ?
Else would this be correct?
0,30 * * * * mysql -h localhost -u root -p -e "UPDATE konto SET field = 'pengar' WHERE pengar = 'pengar' + 30000"
exampel:
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "this"; <-------this as -n this ?
Else would this be correct?
0,30 * * * * mysql -h localhost -u root -p -e "UPDATE konto SET field = 'pengar' WHERE pengar = 'pengar' + 30000"
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Cron!!
Your query doesn't look correct, but I don't know what you're doing so I can't say. You can add the db in the query: UPDATE dbname.kontoGoofan wrote:and if its the "connect to database shouldnt database.... be in there aswell...
exampel:
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "this"; <-------this as -n this ?
Else would this be correct?
0,30 * * * * mysql -h localhost -u root -p -e "UPDATE konto SET field = 'pengar' WHERE pengar = 'pengar' + 30000"
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Cron!!
found a temporary way to solve this "only got one problem"
ive made so that i run it throught windows scheduled task manager (as this is so far only a home edition(the thing im trying to do))... it runs the script every 30 min.
my only problem is i dont know what to type as it runs "a program" i guess i have to make a .bat file. so i made a .bat file but i still dont know what to type into hte .bat file is it that i should make it to start a .php page with the information (uppdate ..........).
Do u think that would work? im about to try but if u think it wount then tell me
ive made so that i run it throught windows scheduled task manager (as this is so far only a home edition(the thing im trying to do))... it runs the script every 30 min.
my only problem is i dont know what to type as it runs "a program" i guess i have to make a .bat file. so i made a .bat file but i still dont know what to type into hte .bat file is it that i should make it to start a .php page with the information (uppdate ..........).
Do u think that would work? im about to try but if u think it wount then tell me
Last edited by Goofan on Tue Dec 01, 2009 12:52 pm, edited 1 time in total.
Re: Cron!!
ok so that didnt really work...
i told a bat file this:
content of .bat:
and i set into Uppdate_money.php:
see anything i should change or make diffrent?
im not totaly sure about the .bat file if its correct with its content...
-Thanks in advance
-Thomas
i told a bat file this:
content of .bat:
Code: Select all
C:\Program Files\wamp\www\www\Projektarbete\Uppdate_money.php
Code: Select all
<?php
include "database.php";//Fil för databasinställning.
// Build our query
$sql1 = "SELECT * FROM konto";
$result = mysql_query($sql) or die(mysql_error());//Välj all info i tall. //hämtar all info från tabell
while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
{
$pengar = $row['pengar'];
}
$sql="UPDATE konto SET pengar=($pengar + 30000)";//Sätt upp SQL fråga.
?>
im not totaly sure about the .bat file if its correct with its content...
-Thanks in advance
-Thomas
Last edited by Goofan on Wed Dec 02, 2009 7:41 am, edited 1 time in total.
Re: .Bat to run .php page !help!
any help appreciated:D
i runned it and well nothing happend...
i runned it and well nothing happend...
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: .Bat to run .php page !help!
Hmm.. stick with your other thread (you were headed in the right direction) and this is basically a duplicate.
Re: .Bat to run .php page !help!
which one do u mean and how do u mean? plz help...
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: .Bat to run .php page !help!
What I meant was your best bet is to use cron (linux) or task scheduler (windows) to directly invoke the CLI (Command Line Interface). Not need for a .bat file -- however -- you can find an example in the manual (scroll down to "Example #9 Batch file to run a command line PHP script (script.bat)").
You simply don't pass the location of the PHP file, since the file itself needs to be interpreted by the PHP engine. Take a look here on how you would call the your program in CLI.
I suggest you let me know which one of your threads you want me to close, since they are both for the same issue.
You simply don't pass the location of the PHP file, since the file itself needs to be interpreted by the PHP engine. Take a look here on how you would call the your program in CLI.
I suggest you let me know which one of your threads you want me to close, since they are both for the same issue.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: .Bat to run .php page !help!
I told myself I was going to leave this thread, but...
First, you need to learn something about what you're doing in PHP and SQL. What you have in the PHP file is never going to work. Second, something like this in the batch file should work:
First, you need to learn something about what you're doing in PHP and SQL. What you have in the PHP file is never going to work. Second, something like this in the batch file should work:
Code: Select all
c:\path\to\mysql -h localhost -u root -e "UPDATE dbname.konto SET pengar = (pengar + 30000)"mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: .Bat to run .php page !help!
John Cartwright wrote:What I meant was your best bet is to use cron (linux) or task scheduler (windows) to directly invoke the CLI (Command Line Interface). Not need for a .bat file -- however -- you can find an example in the manual (scroll down to "Example #9 Batch file to run a command line PHP script (script.bat)").
You simply don't pass the location of the PHP file, since the file itself needs to be interpreted by the PHP engine. Take a look here on how you would call the your program in CLI.
I suggest you let me know which one of your threads you want me to close, since they are both for the same issue.
besides cant get "any" of the two "idés to work
You can close the other one
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: .Bat to run .php page !help!
oh now i know why you locked it. 
goofan, its daedalus!
where are you at with this? im here to help.
goofan, its daedalus!
where are you at with this? im here to help.