triggering php scripts using cron
Moderator: General Moderators
-
dannymc1983
- Forum Commoner
- Posts: 80
- Joined: Wed Feb 16, 2005 7:24 am
triggering php scripts using cron
im currently setting up a script wherby emails to be sent out from a website are stored in a database. then using a cron program the database is checked for new emails every 15 mins and these emails are then sent. The only problem i have is that to run a script i have to run it in a browser under the address "http://localhost/'the name of my script .php'"
this would mean that to execute the script i would have to enter the location of the web browser with the above address as a parameter in the cron file.
this would execute the script but it means a new browser is opened every 15 mins which i can see, which after a while results in a lot of open browsers!
is there anyway i can run a php script without having to run it in a web browser or is there a way that the script can just simply run in the background without it being visible to the user?? any help would be appreciated thanks!
this would mean that to execute the script i would have to enter the location of the web browser with the above address as a parameter in the cron file.
this would execute the script but it means a new browser is opened every 15 mins which i can see, which after a while results in a lot of open browsers!
is there anyway i can run a php script without having to run it in a web browser or is there a way that the script can just simply run in the background without it being visible to the user?? any help would be appreciated thanks!
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I'm guessing you're running this "cron" under Windows.. in which case, you can run the script through the command line interface to php, which will open a DOS emulation window briefly, if I remember correctly. If these are run under a UNIX machine, then simply adding a shebang (#!) line as the first line in the file, will allow the OS to call your command line interface for you by simply calling the script.
-
dannymc1983
- Forum Commoner
- Posts: 80
- Joined: Wed Feb 16, 2005 7:24 am
Yes im running windows, but as i said in my first post the only way i can run a php script is in a web browser under my server:
do you know of a way i can run my php scirpts without having to open them in a browser?
say for example if i have a .php file on my desktop and i try to open it then none of the php code in that file will be executed in it (and i dont know why).The only problem i have is that to run a script i have to run it in a browser under the address "http://localhost/'the name of my script .php
do you know of a way i can run my php scirpts without having to open them in a browser?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
In command line:
You can run it as cron by putting the command into Scheduled Tasks under the Windows Control Panel 
Code: Select all
# C:\> c:\php\php.exe c:\webs_dir\phpfile.php-
dannymc1983
- Forum Commoner
- Posts: 80
- Joined: Wed Feb 16, 2005 7:24 am
ok thanks for that. tried running the script in the command line but its giving me a fatal error thats not appearing when i run it in the web browser! it works fine in the browser.
it doesnt seem to recognise a method thats being called (the method is part of another file). maybe this could be because the includes are treated differently when running under the command line?
the script im trying to run by the way is a pear script, mail_queue, for storing emails in a database and then sending them when a cron task executes
it doesnt seem to recognise a method thats being called (the method is part of another file). maybe this could be because the includes are treated differently when running under the command line?
the script im trying to run by the way is a pear script, mail_queue, for storing emails in a database and then sending them when a cron task executes
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
You may need to specify the location of php.ini if it requires settings made in there.
Use the -c (lowercase "c") flag to do this.
EDIT | Reason: PHP running in CLI doesn't load php.ini, it just uses the defaults.
Use the -c (lowercase "c") flag to do this.
Code: Select all
# C:\> c:\php\php.exe -c c:\windows\php.ini -f c:\webs_dir\phpfile.php-
dannymc1983
- Forum Commoner
- Posts: 80
- Joined: Wed Feb 16, 2005 7:24 am
there is also a way to configure windows so that when you run a php script (either by console or double click) that it tries to execute it with php.exe. i'd have to do some searching on the forums, but i posted on this method somewhere...
EDIT : Found it. You can go here and follow the links supplied.
EDIT : Found it. You can go here and follow the links supplied.
-
dannymc1983
- Forum Commoner
- Posts: 80
- Joined: Wed Feb 16, 2005 7:24 am
ok thanks, i already have a cron program (nncron lite) which is basic enough but it does the job.
do you know of any way of setting tasks so that they run in the backgound, so for example if i didnt want the dos prompt window to appear while my cron task is executing?? there must some option you can set on the command line which will take care of this. would you know anything about this?
do you know of any way of setting tasks so that they run in the backgound, so for example if i didnt want the dos prompt window to appear while my cron task is executing?? there must some option you can set on the command line which will take care of this. would you know anything about this?
-
dannymc1983
- Forum Commoner
- Posts: 80
- Joined: Wed Feb 16, 2005 7:24 am
-
dannymc1983
- Forum Commoner
- Posts: 80
- Joined: Wed Feb 16, 2005 7:24 am
ok, i tried using the following command:
and the dos window is still appearing (it is not running in background mode). any other suggestions?
Code: Select all
c:\wamp\php\php-cgi.exe -c c:\wamp\apache\php.ini -q c:\wamp\www\send_example.php