Hi all. Here's my situation and how I'm solving it. Please let me know if my methods look good or if there is a better way of doing it.

A local business around here has a drawing each day where they pick some customers' names to win something. The winners' names are posted on a web page each day. I wanted to automate getting the results, specifically if my name is on the list.

I wrote up a PHP script that does the following: First it fetches the content of the page using curl_exec. Then it searches those results using stristr for the name(s) that I'm interested in. If it finds them, it appends the name(s) to a string of winners and sets a flag to true. After checking for the names, if the flag is true, I use mail to send the results, including the names, to my email. I have a cron job set up to wget the page with the script every morning.


Is that pretty much a reasonable way of doing it, or would there be a better way?

Recommended Answers

All 2 Replies

Sounds good - I use a similar system to send me a message when a particular radio station plays the same song twice in one day (first caller gets $1,000). The songs are posted on their web site.

Anyway, back to what you're doing: You could improve the cron side of things. Instead of using cron to call wget, which calls the PHP page (via a Web server), why not modify your PHP file like so:

#!/usr/bin/php
<?php

// your PHP code here

?>

Ensure the file has execute permissions (chmod 700 will work becase that gives you permissions to read, write and execute).

Then just have cron call that file instead of wget. (That file is effectively an executable script).

Note: You may need to change /usr/bin/php to match the path of wherever PHP happens to be installed on your server.

That's a good idea. Plus, then I could eliminate my other cron job of rm-ing the file that I fetched.

Ever won that thousand bucks?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.