WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Newbie Notes #8 - A cron trick
Categories : PHP, CURL, Beginner Guides Click here to Update Your Picture
Simon Booth
Date : Apr 23rd 2004
Grade : 2 of 5 (graded 5 times)
Viewed : 7215
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Simon Booth
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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