I'm fairly new to PHP. I need to run a function on my PHP site on a daily basis. I have seen posts on how to do this under Linux, but I'm running the PHP site on Windows Server 2012 under IIS. How can I create a PHP function and then run it at a certain time each day?
You could use Task Scheduler on the server to run a batch file that runs the PHP script via command line at a regular interval, which i hope should solve your problem.
Run Cron Job on PHP Script, on localhost in Windows
Create script.bat file with below Code
"C:\wamp\bin\php\php5.4.12\php.exe" -f "C:\wamp\www\website\my_process.php"
Change wamp path to your iis path
Download & Install Zcron From Below Link
http://www.z-cron.com/download.html
Create New Task select your script.bat file and set timer
Related
I have installed cacti php in my ubuntu 14.04.
Cacti create rrd file and periodically update it after each 5 mins.
sample rrd file like /var/lib/cacti/rra/localhost_hdd_free_14.rrd
I need some help.
Now I want to know this script path that create and update this rrd file in
background.Means, I want to know where this script is located in cacti
environment.
This peridic update is continue even I stop the apache server.
It means it running as cron job.
But when I run this command "crontab -e -u root"
it says that there is no cron job for this user.
I want to find out how the data is collected across network using snmp
to create graph for different device.
Please help me to find out this cron scipt.
Here what I have find.
You can get the list of cronjob running under Linux Ubuntu in following directory.
/etc/cron.d/ directory.
Under this directory,you wll find the all cronjob running for cacti.You can edit desired file if you have permission.Then do the change what you want like changing interval for cron,changing target file that you want run.
How would you run a windows task schedule to open a webpage, post login information and then run the url?
Background:
CRM has crons that were setup for a linux only. It has a manager where I can run the jobs as well manually. I want to run the web url that does these jobs manually through the windows server but requires that each time it connect it login with a specific user.
How would I setup a scheduled task on windows server that :
1. Opens and Logs into page then runs the url for the manual job.
Runs every minute
So essentially it needs to look like this:
http://thewebsitename.com/?username=someuser&password=apass
http://thewebsitename.com/theurltorunjobmanually.php
Can scheduled tasks run a php command instead as well? For example if I set up a WGET script, could the scheduler run that php script? Have not been able to figure out how to do this, linux seems to be pretty easy in this scenario
This could be as simple as:
Download wget for Windows
Create a batch file with the following contents:
wget --post-data "username=someuser&password=apass" http://thewebsitename.com/
wget http://thewebsitename.com/theurltorunjobmanually.php
You also asked about running a PHP script via the scheduled task, you can add this line to the batch script:
C:\path\to\PHP.exe script.php
Not sure if you're looking for methodology or an actual solution, but we have a process somewhat like this where we need to login to our CRM and run an upload, task creation process at regular intervals. Used to be manual but now we use an automation software product, Foxtrot. You can find it here for whatever it is worth: http://www.enablesoft.com/foxtrot-professional/
You can put the cURL or wget commands in a batch file or PowerShell script and have the Windows Task Scheduler call it.
I have an nginx server installed on Windows Server and I am wondering how can I run a PHP script using scheduled tasks or at every minute? Also how can I use include() within that script? Will including dirname(__FILE__); before the include path work the same way as it does with cron?
I have a project, i need to do this
a desktop application sends a txt file with a number to the web server every 5 seconds
the web server opens that file and saves the number in a database
the thing is that i need it to work 24/7 , even if the user hasn't logged in.
the desktop application already works, what can I do?
You should use a cron to do this. Here's an article explaining how to set them up in linux:
http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_using_crontab/
In case you're running this on windows:
What is the Windows version of cron?
Mac is similar to linux:
http://benr75.com/pages/using_crontab_mac_os_x_unix_linux
use Unix Chron to plan a php job that fits your needs
What you're trying to do is not actually a web server function, per se, (there isn't a request to serve) you just want to run a PHP script on a pre-determined schedule. To do that, you should run a scheduled job (cron on non-windows, Scheduled Task on Windows).
We use Windows, so here's how you set up a scheduled task for a php script to run when you need it to:
On the web server, from Control Panel, create a new Schedule Task
Set the Run value to wherever PHP is installed and the script you want to run:
"C:\Program Files\Php5\php.exe" C:\webserver\scripts\myphpfile.php
Set the Start in to wherever your php file is:
C:\webserver\scripts\
Set up the rest of the Schedule Task options to your needs.
I need to run a php script at the scheduled time daily to update some fields in database and to send automated email. How I can do this?
Is it possible to write some service in XAMP server to run the script daily at scheduled time? I have no idea how to update database and send email automatically at the scheduled time. Can any one share some ideas or concepts?
I am using PHP and MySQL running in Linux Server.
You should use a Cron job to do it. Check out the examples on the Wikipedia page.
The Cron Job should call a script using the php executable that runs the necessary task.
Just create the script that does the required job, test it by hitting the URL in your browser once you are sure it works right. Copy the URL and add a Cronjob
Then schedule this command to run at whatever time you want to run
php ABSOLUTE_URL_TO_SCRIPT >> logfile
The log file is optional. But it will give you a chance to see what happened.
For example if you want to run your script every 4 hours, and assuming your script is at http://localhost/work/scripty.php and assuming that your http root is /var/www,
you would run "crontab -e" in terminal and add the following line:
* */4 * * * php /var/www/work/scripty.php
If you need more information just comment I will update the answer.
PHP cannot run script by itself,since php doesn't have daemons like python !!
So you have to take OS help to invoke your custom script .
For example in linux :
(example.sh)
export USE_PHP=php
cd $SCRIPT_ROOTDIR
$USE_PHP -f cronfile.php service="checkdatabase"
(service is the parameter passed to your cronfile).
For setting up cron jobs ,have a look at this link
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
In Linux, We can create .sh file and can give a specific time to run that is called cron job.
SO should use this method just make a shell file and give a time period to it.
You should take a help with linux expert for that.
Use the following: Cron Job