|
|
|
NewbieNotes is a little series of tips for people who are new to PHP to give them a few handy tips that the more experienced of us use often
It's often desirable to perform certain tasks once a day, usually in the early hours of the morning. Such tasks are usually handled by PERL scripts, but PHP is equally up to the task.
All you need to do is create a web page that performs whatever task you wish to perform and somehow automate it being loaded at the given time
There is a small trick involved in running a PHP script in the middle of the night when nobody is around to start it going. The best thing about this method is that you don't need to have the command line version of PHP on the server you're using - frequently an omission with hosted sites.
As long as you can either install or already have access to a program called CURL and can set up a cron job everything else is possible.
CURL is an excellent little program, available from http://curl.haxx.se, that grabs web pages off the net, optionally saving them to a file.
Using CURL you can run your script using a command line along the lines of...
curl http://www.myserver.dom/myscript.pghp > output.htm
If you insert this command, with your script as the page loaded into your cron file it's a simple matter to run daily/nightly routines written entirely in PHP |
|
| Cut your MySQL Connections to 1 line of code Categories : PHP, Beginner Guides, Databases, MySQL | | | Basic Authentication with sessions Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions | | | Introduction to Language Files Categories : PHP, Filesystem, Beginner Guides | | | News management class Categories : PHP, PHP Classes, Beginner Guides | | | A flat file counter Categories : PHP, Cookies, Filesystem, Beginner Guides | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | | | Different Call User Functions Categories : PHP, Functions, Beginner Guides | | | Creating a Language File Categories : PHP, Beginner Guides, Filesystem | | | a PHP Function to Get only the filename (remove the extension) using regular expressions. Categories : PHP, Regexps, Beginner Guides | | | A beginner's session handling class Categories : PHP, PHP Classes, Sessions, Beginner Guides | | | email new items in db Categories : PHP, Email, Databases, MySQL, Beginner Guides | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | | | PHP based Contact email form with multiple recipients, text file based, supports departments. Categories : PHP, Email, Beginner Guides, Filesystem | | | Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides | | | These PHP Classes Check if a host is alive using various methods. Categories : PHP, PHP Classes, Sockets, CURL | |
| | | | Valics Lehel wrote : 1084
An another solution is to programming in that way, that once a day, your 1st visitor, start a "fake cron" script. So teoretically the cron will be the first visitor.
We use this in sites where we don`t have access to CRON table. Is not very nice, because on large sites, that specific user can wait to long for page, but we did not find an another way.
Also cURL is not installed on all servers. So what you do if is not installed?
Also for people who do "crons" like this, http://www.mydomain.com/cron_script.php and have a possibilities to call from shell, better use
#!/usr/bin/php -q
<?php
if ($_SERVER["HTTP_ACCEPT"] != `` && $_SERVER["HTTP_ACCEPT_LANGUAGE"] != ``) {
die(`This script can only be run via a shel terminal, not via your browser.`);
exit();
}
script continue here.
| | | | Simon Booth wrote :1085
The point I was making wathe usefullness of curl
You can always instll CURL, even on a hosted box. Then ouy can run a zscript to automate just about anything you like
If you fail to understand this - fine - I`m just tryig to help people out
| |
|
|
|