PHP in the Command Line

Written by Robert Plank


Continued from page 1

Tip: Pipe your cron jobs to /dev/null if you aren't doing anything withrepparttar output, because some hosts e-mail yourepparttar 107759 results and no one needs an extra piece of useless e-mail every day.

Just change http://www.google.com torepparttar 107760 page of your choice. However it's important to know thatrepparttar 107761 "archive" you're taking will only be a snapshot of that page on a particular day.

What I mean by that is, if you're archiving a blog page every day, this archiver won't archive that page on a particular day, it'll just be archiving what was there at that time. So it's not useful for everything, but it's good if you have access to a page that changes constantly, once a day, whose results you'd like to store.

Add that line above into your crontab file. These days every host has a control panel so there should be a place in there to add cron jobs. If you'd likerepparttar 107762 archiver to run at a time other than midnight, or if it should run weekly, monthly, or whatever, try this tool I've made for you:

http://www.robertplank.com/cron

I've designed itrepparttar 107763 same way Task Scheduler is setup, you can enter a certain time, run only on weekdays, run only on certain days ofrepparttar 107764 week. Anything you want.

This tip doesn't take care of everything... for example, wget won't saverepparttar 107765 images on a page unless they're referenced by full URLs. Inrepparttar 107766 next installment of this article series I'll be showing you how you can use PHP to make up for some ofrepparttar 107767 things wget can't do (like grabbing images).

Here's my solution: http://www.jumpx.com utorials/commandline/get.zip

It's notrepparttar 107768 most perfect script inrepparttar 107769 world, but it should do what you want most ofrepparttar 107770 time. If you'd like to delve into what it does, I've added comments within so you can see what it does. I've commented allrepparttar 107771 functions and a few ofrepparttar 107772 important parts ofrepparttar 107773 code.

ARGUMENTS (NOT THE SHOUTING KIND)

But wait, you want to use it in a crontab, which is run fromrepparttar 107774 command line. You can't just do something like:

php get.php?url=http://www.google.com

Because it'll try looking for a *file* named all that, complete withrepparttar 107775 question mark and all. So what if you have ten different URLs to grab off ten different crontabs, but you only want one script.

How would you do all that? It's a long brutal ordeal so prepare yourself. Ready?

php get.php url=http://www.google.com

Yeah, that's all there is to it. PHP's pretty cool like that, it takesrepparttar 107776 arguments afterrepparttar 107777 file name and stores them inrepparttar 107778 same array you'd check anyway.

One thing you might notice is that every time you run PHP fromrepparttar 107779 command line, it gives you something like this:

Content-type: text/html X-Powered-By: PHP/4.3.3

your output here...

Those first couple of lines arerepparttar 107780 HTTP headers. But we're not using HTTP (not loading it from a browser), so inrepparttar 107781 command line it's better to call php withrepparttar 107782 "-q" option, like this:

php -q get.php url=http://www.google.com

The "q" stands for quiet, and will refrain from giving yourepparttar 107783 HTTP headers. If you're just pipingrepparttar 107784 script to /dev/null (to nothing) in a crontab, it doesn't really make a difference but you should try to make this a habit when running PHP fromrepparttar 107785 command line.

That's enough for you to at least get started. If you still feel liking poking about withrepparttar 107786 things PHP can do inrepparttar 107787 command line, you can try prompting a user for keyboard input, like this:

echo "Give me your name: "; $data = fopen("php://stdin", "rb");

while (1==1) { $chunk = fread($data, 1); if ($chunk == " " || $chunk == " ") break; $input .= $chunk; } fclose($data);

echo "Hello $input! ";

?>

Remember, that only works when PHP is run fromrepparttar 107788 shell.

If you have PHP installed in Windows on a local machine of yours, you can also see what happens when you try to read (and write) to filehandles like "COM1:" and "LPT1:" ... yep, you guessed it,repparttar 107789 serial port and printer port. If PHP isn't installed onrepparttar 107790 computer you're using now then don't bother. But it is possible to use PHP to print and interact with your peripherals as well.

You're welcome.

Robert Plank is the creator of Lightning Track, Redirect Pro, Rotatorblaze, and others.

An easy way to display the content saved by this article's script is explained in chapters 15 and 16 of his book, "Simple PHP": http://www.simplephp.com

You may reprint this article in full in your newsletter or web site.


Setting Up An Internet Connection

Written by Robb Kimmer


Continued from page 1

Now you have a working modem/TA you are ready to configurerepparttar connection to your ISP.

Connecting up:

First, make sure that there is no other application running on your computer. Checkrepparttar 107758 Task bar. If you see another application, right click it and Close.

You will need to have your ISP dial-up number, account username and password to hand. If you don’t know what these are, just telephonerepparttar 107759 ISP and they will give you this information. If they say something about not needing it because their CDROM does it all for you automatically, tell them that you want it anyway. Don’t get into a discussion aboutrepparttar 107760 configuration ofrepparttar 107761 Internet connection. They won’t understand what you are talking about. Just palm them off with some guff and getrepparttar 107762 information you want. After all, you only need them to give you access torepparttar 107763 Internet/WWW, after that, you don’t need them at all. Your ISP is a simple ‘gateway’ torepparttar 107764 Internet, that’s all. They have little else, other than advertising, to offer.

Now we have allrepparttar 107765 information, grab a quick coffee and then get settled to dorepparttar 107766 business! Lockrepparttar 107767 door and ignore all requests for access other than those from angels bearing drinks and snacks. Priorities dear reader, priorities.

With all things ‘computer’ there is always a dozen different ways and routes to achieverepparttar 107768 same result. I am going to set out just one way of doingrepparttar 107769 job. There are others, but I am going to show yourepparttar 107770 easiest and most practical method.

Right click onrepparttar 107771 Desktop icon named Network Neighbourhood or My Network Places. Choose Properties and you will seerepparttar 107772 Create New Connection icon orrepparttar 107773 New Connection icon. Double click it and a connection Wizard will start.

Now that you haverepparttar 107774 Wizard onrepparttar 107775 screen, choose Connect To The Internet. This will lead on to a dialog box that will ask you if you want to Choose From A List Of Service Providers, Use The CD I Got From An ISP or Set Up My Connection Manually. Choose Manually. Next you will be probably be asked which kind of connection you have. Choose to connect using a Modem. This will also berepparttar 107776 choice for your ISDN terminal Adapter (TA). You will then be asked which modem you want to use (if you have more than one connected to your computer). You will probably only have one, so select that one. You will be asked to typerepparttar 107777 name of your ISP orrepparttar 107778 name of this connection. It’srepparttar 107779 same thing. So type something that you will recognise when you want to make a connection. Now you will have to type inrepparttar 107780 telephone number that your ISP gave you. Just type it right in without any spaces or hyphens. Next you will be presented with a dialog box that will ask you to enterrepparttar 107781 username and password forrepparttar 107782 connection. These are your Internet account details that your ISP gave you. Fill inrepparttar 107783 boxes and make any other choices that are presented to you. If you are using XP uncheckrepparttar 107784 Firewall checkbox. If you want to userepparttar 107785 Microsoft software Firewall, leaverepparttar 107786 box checked. However, there are far better and more effective Firewall programs to use thanrepparttar 107787 built in software that Microsoft provides. But,repparttar 107788 choice is yours. Now you will be atrepparttar 107789 end ofrepparttar 107790 Wizard and you may be asked if you want a shortcut on your Desktop. Makerepparttar 107791 choice and click onrepparttar 107792 Finish button.

Great! If all has configured properly it’s time to test your handiwork. Go to your Desktop and right-click on Network Neighbourhood or My Network Places. Choose Properties and you will seerepparttar 107793 connections that are currently setup on your computer. You probably only have this one. If you are on a network you will see your Local Area Network connection icon too. Double click onrepparttar 107794 icon named withrepparttar 107795 title you gave it duringrepparttar 107796 configuration. The connection box will appear. Make sure that all is as it should be and click Dial. There will be a slight delay and then you will hearrepparttar 107797 modem dialling out to your ISP. If you mutedrepparttar 107798 modem/TA speaker, you will be able to check that things are happening by watchingrepparttar 107799 LEDs flashing onrepparttar 107800 front ofrepparttar 107801 modem/TA unit. You will have a bit of a wait whilerepparttar 107802 modems talk to each other and then you should get authenticated ontorepparttar 107803 ISP’s system. Once that is done you will see a message atrepparttar 107804 bottom right of your screen that tells you that you are connected and what bandwidth you have been allocated. Start your browser and enjoy.

Notice that your browser is unaltered, you don’t have to go to a special web page and you can use any search engine you like. You won’t have any spy-ware lurking in your system and your ISP will have no control over you and your activities at all.

Just to whet your appetite (but beware)…

If you have a small network at home or at your office, you can configure one computer to provide an Internet connection for allrepparttar 107805 others and set it up to dial up on demand when someone on another computer starts their web browser. This process is called Internet Connection Sharing and Demand Dialling. Quite a mouthful, but not difficult to set up. However, there are a couple of technical details that you will need to understand concerning protocols. So, be careful if you find yourself trying this out. You may end up losingrepparttar 107806 connections to your other computers and ruiningrepparttar 107807 network connectivity. To be quite honest, ICS is not a particularly efficient method of multiple Internet connectivity. There are far easier and less fraught ways of providing that kind of service.

Get yourself a PopUp killer and a decent firewall. I suggest Zone Alarm Pro forrepparttar 107808 firewall. I also suggest that you get a copy of AdAware. It will protect you from spy-ware and other nasties thatrepparttar 107809 bad guys will try and sneak into your operating system when you are onrepparttar 107810 Web. You can set your browser security to resist cookies and Java. But, that will severely restrict your experience and will stop allrepparttar 107811 fun animations andrepparttar 107812 like. So, don’t be too restrictive, just getrepparttar 107813 right software to protect you, then you can free-up your browser and see and experience allrepparttar 107814 fantastic stuff that is out there in Web-Land. You can obtain all these applications by entering their names into a search engine, say Google for instance, and you will receive a list of URLs to contact where you can downloadrepparttar 107815 Shareware versions to try before you buy.

Robb Kimmer is an experienced networks system engineer and IT instructor. He has worked for over 14 years in the IT industry in both the UK and USA. He is a member of the British Computer Society Elite Group. Robb writes for several magazines and you can get more information about him on the WWW.


    <Back to Page 1
 
ImproveHomeLife.com © 2005
Terms of Use