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.
Related
I have a simple PHP script that checks the PDO SQL connection and the script does something after that.
The problem is when I run it as a scheduled task from windows schedule even from a batch file or directly by running from the scheduler with php.exe -f "script file"
the command prompt window appears and this is relay annoying.
Is it possible to disable the cmd popup when running the script from scheduler?
On Task Properties, in General Tab, there is a option called as "
Security Options
On this options, choose the second option which is
Run whether user is logged on or not
After saving, it will ask your admin credentials. Enter your credentials, then your scheduler will not show any cmd window.
Try use wget with -q. I have a machine with Windows Server 2012 + Apache and a scheduled task for every 5 minutes and using wget it didn't show any command prompt window.
I downloaded wget from http://gnuwin32.sourceforge.net/packages/wget.htm
It is a tricky thing. You can try to use the task.exe tool from the PHP SDK under the default task scheduler. Another option were to use an alternative cron implementation, for example a UNIX like nnCron.
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
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
I have written a PHP script which generates an SQL file containing all tables in my database.
What I want to do is execute this script daily or every n days. I have read about cron jobs but I am using Windows. How can I automate the script execution on the server?
You'll need to add a scheduled task to call the URL.
First of all, read up here:
MS KB - this is for Windows XP.
Second, you'll need some way to call the URL - i'd recommend using something like wget - this way you can call the URL and save the output to a file, so you can see what the debug output is. You can get hold of wget on this page.
Final step is, as Gabriel says, write a batch file to tie all this up, then away you go.
e: wget is pretty simple to use, but if you have any issues, leave a comment and I'll help out.
ee: thinking about it, you don't even really need a batch file, and could just call wget directly..
add a scheduled task to request the url. either using a batch file or a script file (WSH).
http://blog.netnerds.net/2007/01/vbscript-download-and-save-a-binary-file/
this script will allow you to download binary data from a web source. Modify it to work for you particular case. This vbs file can either be run directly or executed from within a script. Alternately you do not have to save the file using the script, you can just output the contents (WScript.Echo objXMLHTTP.ResponseBody) and utilize the CMD out to file argument:
cscript download.vbs > logfile.log
save that bad boy in a .bat file somewhere useful and call it in the scheduler: http://lifehacker.com/153089/hack-attack-using-windows-scheduled-tasks
Cron is not always available on many hosting accounts.
But try this:
http://www.phpjobscheduler.co.uk/
its free, has a useful interface so you can see all the scheduled tasks and will run on any host that provides php and mysql.
You can use ATrigger scheduling service. A PHP library is also available to create scheduled tasks without overhead. Reporting, Analytics, Error Handling and more benefits.
Disclaimer: I was among the ATrigger team. It's a freeware and I have not any commercial purpose.
Windows doesn't have cron, but it does come with the 'at' command. It's not as flexible as cron, but it will allow you to schedule arbitrary tasks for execution from the command line.
Yes, You can schedule and execute your php script on windows to run automatically. In linux like os u will have cron but on windows u can schedule task using task scheduler.
If your code is in remote hosted server then create a cron-job for the same.
Else if in local then use a scheduled task in windows.Its easy to implement.I am having servers with so many scheduled tasks running.