Windows Server 2012 PHP cron - php

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?

Related

Creating A Scheduled Task on PHP Running Under IIS

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

How to make the hosting server run specific PHP code in timely manner?

I'm new to PHP and web applications. I have PHP code which collects info, from 5 huge XML files provided by other websites into a private MySQL database.
These XML files are updated and changed over time, and I want my database to be refreshed every day at 3:00 AM.
Can I make the hosting server run the PHP code by itsself? How?
As Hobo Sapiens says:
Create a CRON Job
Put a shell script in one of these folders: /etc/cron.daily, /etc/cron.hourly, /etc/cron.monthly or /etc/cron.weekly based on how often you want the script to run.
The shell script should look something like this:
#!/bin/sh
php -q htdocs/file.php
For more specific timings take a look at How do I set up a Cron job?.
If you don't have SSH access to the server, you could also set up a cron job locally to ping the remote server using wget --spider or curl.
You can use CRON jobs. Cron will automate your commands on a specific time.
The software utility Cron is a time-based job scheduler in Unix-like computer operating systems.
Read more about CRON jobs

Using Lynx to run a PHP script in CentOS

I need to use an Apache handler to run a PHP script, rather than running it through CLI. I'm using APC user cache, which stores variables using the Apache process. If I run my PHP script through CLI, then it won't have access to the APC variables.
A possible solution is creating a directory restricted to localhost and putting my scripts in there. Then, I can use a browser to run the PHP scripts. However, I'm not too experienced with Linux and I don't know how to implement this. Here's how I need it to work:
One of the cron job fires.
The cron job opens the PHP script using a web browser.
After the PHP script is finished processing, the web browser closes.
I don't know how to close the browser once the task is finished. Also, multiple PHP scripts will be running simultaneously (called by different cron jobs), I'm not sure how this will work. I'm using the Lynx browser on CentOS.
In Debian/Ubuntu I can run a script using lynx, say
/usr/bin/lynx -source 'url'
For eg:
/usr/bin/lynx -source http://google.com
Once execution is completed, the browser quits default.

Run PHP script in background without open it in browser

Can we run PHP script just like jar's files.I want to execute PHP script in background without open it in browser.Is this thing possible ?
Using Crons we can run. Make a batch file with php commands and run it through task scheduler if you are using windows OS or run it as cron for apache.

How do i keep a php script active even if nobody opened the website?

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.

Categories