Page 1 of 2
work without opening pages
Posted: Fri Oct 29, 2004 11:29 am
by Tolarianacademy
hi,
is possible to create some php pages which works also if no one open it?
something that automatically works.
thx

Posted: Fri Oct 29, 2004 11:44 am
by andre_c
When does it work then?
I assume that you mean a regular program that you start without a webpage. Try searching for PHP CLI.
Re: work without opening pages
Posted: Fri Oct 29, 2004 11:49 am
by objectifier
Tolarianacademy wrote:hi,
is possible to create some php pages which works also if no one open it?
something that automatically works.
thx

No problem! Normally PHP is used with web pages but that is not a requirement. PHP can do just about anything you need and you don't have tell it to send output to a web page. There are also tools available that let you build GUI interfaces to PHP so they function like normal GUI programs on a Mac, Windows, etc.
Posted: Fri Oct 29, 2004 1:43 pm
by Tolarianacademy
Thx a lot!
bye

Posted: Sat Oct 30, 2004 3:24 am
by Tolarianacademy
Is possible to do something that, for exaple, starts every hour?
thx

Posted: Sat Oct 30, 2004 6:19 am
by swdev
Hi Tolarianacademy
Depends on what operating system you are running on.
If you are running on a *nix OS, then 'cron' is your man.
If you are running on Windoze, the you can set up a job via the task scheduler, or user the 'at' command.
If you are using another operating system, search the manuals.
Hope this helps
swdev
Posted: Sat Oct 30, 2004 12:55 pm
by Shendemiar
Cron daemon in unix can be set to call any web page with various settings.
Handy for running php scripts online or locally to do some maintanance etc.
Posted: Sun Oct 31, 2004 8:43 am
by Tolarianacademy
I explain better my problem:
I wont something that automatically check into the database a time value and if it is > than 30 minutes do something.
and it for all users.
so for each user read into the database the time value, check it and eventualy do something.
Posted: Sun Oct 31, 2004 9:41 am
by swdev
do you mean you want something like
run a script every , say, 5 minutes
This script would
read a timestamp from the database
If this timestap was more that 30 minutes ago then
for each user in the database
do some action
end for
update timestamp int he database
end if
or do you mean something like this
run a script every , say, 5 minutes
This script would
for each user in the database
read the timestamp for this user
if this user's timestamp is more than 30 minutes old
do some action
update this user's timestamp
endif
end for
Posted: Sun Oct 31, 2004 11:04 am
by Tolarianacademy
the second one!

and running every minute.
every minute:
for each user
look at the database the timestamp
if > 30 minutes
do something
end if
end for
Posted: Sun Oct 31, 2004 12:14 pm
by swdev
You must find out whether your host will
a) let you run automated tasks
b) let you run PHP from the command line as part of that task
assuming you can, then the logic you require goes something like
Code: Select all
--- work out time parameters
$current_time = get current time
$old_time = $ current_time - 30 minutes
--- connect to MySQL server - assumes a MySQL database
$link = mysql_connect ($hostname, $username, $password) or die('Failed To Connect ' . mysqlerror());
--- select database to use
if (false == mysql_select_database ($database_name))
{
die ('Failed To Select Database ' . $database_name . ' ' . mysqlerror());
}
--- name of table where the usernames and tmestamps are held
$table_name = 'users';
$timestamp_column = 'user_timestamp';
$where_clause = 'timestamp_column < $old_time';
--- create select sql to get list of users for whom to run the required actions
$sql = SELECT userid, timestamp_column FROM $table_name WHERE $where_clause
$result = mysql_query($sql, $link);
if ($result == false)
{
die ('Failed To Run ' . $sql . ' ' . mysqlerror());
}
--- iterate over all the users returne
while ($row = mysql_fetch_assoc($result))
{
do some action for user $rowї'userid'];
}
--- cleanup
mysql_free_result($result);
--- update all those users for which we have just performed the action
$sql = UPDATE $table_name SET timestamp_column = $current_time WHERE $where_clause
$result = mysql_query($sql, $link);
if ($result == false)
{
die ('Failed To Run ' . $sql . ' ' . mysqlerror());
}
mysql_free_result($result);
mysql_close($link);
Posted: Sun Oct 31, 2004 1:14 pm
by Tolarianacademy
thank you very much.
for start the page every minute I have to use CLI?
thanx

Posted: Mon Nov 01, 2004 8:08 am
by Tolarianacademy
I don't understand how culd I say to my server:
"1 minute is passed, please start to read {FILE}"...
thx

Posted: Mon Nov 01, 2004 8:17 am
by swdev
Automatic running of this script. For this to happen, you must ask your webhost if they will allow you to schedule a program to run at a particualr time or frequency. if they do, they will tell you all you need to know on how to set the job up. You should also explain that the job you want to run is writen in PHP so you will need access to the PHP CLI (Command Line Interpreter)
Once you have access to the PHP CLI and the scheduler, you can set up the job. Once it is set up, the server machine will automatically run the job at the scheduled time(s)
Posted: Mon Nov 01, 2004 8:30 am
by Tolarianacademy
ok, all clear.
thx a lot
