| Text Size: |
Site Design (Architecture, Coding, UI, etc.) >> PHP >>
Running PHP Scripts in Command Mode
"For people who make websites" - A List Apart Magazine explores the design, development, and meaning of web content, with a special focus on web standards and best practices.
HTML Validator is a Mozilla extension that adds HTML validation inside Firefox and Mozilla. The number of errors of a HTML page is seen in the form of an icon in the status bar when browsing. The details of the errors are seen when looking the HTML source of the page.
The extension is based on Tidy and OpenSP. Both algorithms were originally developed by the Web Consortium W3C. Both algorithms are embedded inside Mozilla/Firefox and makes the validation locally on your machine, without sending HTML to a third party server.
The extension is based on Tidy and OpenSP. Both algorithms were originally developed by the Web Consortium W3C. Both algorithms are embedded inside Mozilla/Firefox and makes the validation locally on your machine, without sending HTML to a third party server.
This project aims to create an archive of user contributed clip art that can be freely used.
Starting at the beginning, this reference explains everything you need to know about using core JavaScript. It assumes you have the following basic background: a general understanding of the Internet and the World Wide Web and a good working knowledge of HTML. An excellent resource.
Edit your images on the fly online with Splashup, a web-based image editor that integrates with Flickr, Facebook, and Picasa. Splashup offers up a surprising array of image editing tools, far beyond the usual crop of resize and contrast-- you can also edit multiple images, play with filters and layers, use a variety of brushes, and more. Splashup is one of the best image editors in a long line of image editors; i.e., Picnik, Pixoh, and Resizr, to name just a few.[Lifehacker Annotation]
This website will let you:
- Create an XML sitemap format that can be submitted to Google to help them crawl your website better.
- Create a Text sitemap to submit to Yahoo.
- Create a ROR sitemap, which is an independant XML format for any search engine.
- Generate an HTML site map to allow human visitors to easily navigate on your site.
Clearspring's free Launchpad widget builder lets you easily turn your website's content into a widget which site visitors can use to place your content on all the major social media sites (MySpace, FaceBook, Google, hi5, Live, Yahoo, Wordpress, Blogger, etc.). The service also provides tracking and analysis.
This site features online text and html changing, modifying, converting tools designed to save you time making web pages or preparing text for web publication. If you've ever needed to capitalize sentences or convert line breaks to <p> or <br /> then this site can save you needless manual labor. There are other useful tools as well, like the one to uncompress html to make it readable and the ones to uppercase or lowercase text. Basically, the most common tasks that someone who works in an office or does freelance web development might encounter. Most of the tools have been created using javascript so you should be able to change large amounts of text as the processing is done on your computer instead of being limited by a server script.
dTree is a free JavaScript tree menu. That is very simple to set up and use. You don't have to worry about adding pages to the tree in a specific order, which makes it ideal for generating a tree from a database.
webmaster toolkit offers this CSS Menu Generator to generate both the CSS and the HTML code required to produce a text-based yet appealing set of navigation buttons.
Amaya is an open source Web editor endorsed by the W3C. Browsing features are seamlessly integrated with the editing and remote access features in a uniform environment. This follows the original vision of the Web as a space for collaboration and not just a one-way publishing medium.
Amaya started as an HTML + CSS style sheets editor. Since that time it was extended to support XML and an increasing number of XML applications such as the XHTML family, MathML, and SVG. It allows all those vocabularies to be edited simultaneously in compound documents.
Amaya started as an HTML + CSS style sheets editor. Since that time it was extended to support XML and an increasing number of XML applications such as the XHTML family, MathML, and SVG. It allows all those vocabularies to be edited simultaneously in compound documents.
A very flexible unlimited-level, drop down JavaScript menu that uses UL/LI list data formatted with a CSS menu layout. It's powerful, lightweight and extremely easy to use!
CSS Tab Designer is unique and easy to use software to help you design css-based lists and tabs visually and without any programming knowledge required! Read a review.
This document guides you through the process of using JavaScript and the DOM to build a three-state toolbar that accurately and efficiently handles different button states (normal, highlighted, selected), and the interdependencies between them.
The Search Engine Friendly Layouts website has been created for both the webmaster and the search engine optimization specialist. The layouts on the site are all designed to be web standards-compliant, yet also search engine friendly. These layouts have all been created by Adam Senour, and he gives them to you at no cost whatsoever.
Open Source Web Design is a site to download free web design templates and share yours with others. We help make the internet a prettier place.
Some of us have a great eye for complementary colors and matches--and then some of us still don't understand why brown shoes and black pants are a bad idea. For anyone looking to set an image against a complementary background or find a color scheme, Whats Its Color (their grammar, not mine) is a free web app that can help. Upload an image and the site creates a palette page with a complementary background and a list of unique and dominant colors in your image. Photoshop and GIMP gurus might already know how to sift these kind of things already, but the visible color matching could be a boon for presentation slides or small design projects.
This tutorial will teach you all you need to know to be able to craft powerful time-saving regular expressions. It starts with the most basic concepts, so that you can follow this tutorial even if you know nothing at all about regular expressions yet. It will also explain how a regular expression engine works on the inside, and alert you at the consequences. This will help you to understand quickly why a particular regex does not do what you initially expected. It will save you lots of guesswork and head scratching when you need to write more complex regexes.
FastStone Capture is a powerful screen capture utility with built-in editing tools. It allows you to capture anything on the screen including windows, objects, menus, full screen, rectangular/freehand regions and scrolling windows/web pages. It sends captures to editor, file, clipboard, printer, email, Word/PowerPoint document or even your website. Editing tools include resizing, cropping, sharpening, annotating, applying effects, watermarks and many more. It saves captures in BMP, GIF, JPEG, PCX, PNG, TGA, TIFF and PDF formats. Additional features include a small handy capture panel that offers quick access to its capture tools and output options, global hotkeys, automatic filename generation, support for external editors, a color picker, a screen magnifier and a screen ruler.
An online picture editor, pikifx.com emphasizes special effects. You can use it to:
- Resize and Crop,
- Add creative effects,
- Add borders,
- Add creative text
Don't embarrass yourself by busting out the same tired stock clip art for your next Power Point tour de force. WPClipart has a pile of royalty free images to share.
The archive currently has 23,872 images, covering thousands of subjects. A significant portion of them are in lossless formats. The site is organized into categories, but if casual browsing fails to find you the perfect gem you've been searching for there is always keyword based searches. You can even download the entire collection as a single archive, making it easier to use offline. [Lifehacker Annotation]
The archive currently has 23,872 images, covering thousands of subjects. A significant portion of them are in lossless formats. The site is organized into categories, but if casual browsing fails to find you the perfect gem you've been searching for there is always keyword based searches. You can even download the entire collection as a single archive, making it easier to use offline. [Lifehacker Annotation]
If you need a logo but you're lacking the design chops to whip one up, score a free one at LogoInstant. LogoInstant is a design service that cranks out a new logo every day. The logos are completely free for both personal and commercial use and come in a layered Adobe Photoshop source file so you can edit the name or make more advanced changes.[LifeHacker Annotation]
LogoYes is a site offering a flash program to create logos. Just select your industry, a symbol, text, typography and colors for your logo. Once you finish, you can purchase a high-resolution file with your logo for only $69 or include a business card design based on the logo for an additional $30.
99designs helps you run a "design contest", where thousands of designers compete to create the best possible design to meet your needs. All you need is a clear idea of what you want designed and how much you're prepared to pay for it.
If you've been having trouble finding free or Creative Common-licensed photos for use in your projects, Sprixi filters out the fluff to help you find the images you really want.
One of the frustrations of searching for anything on the internet, let alone images, is imprecise search results. If you've ever searched for something and found something completely different—usually because the file name or the associated keywords were strangely or inappropriately applied—then you know what we're talking about.
Sprixi helps circumvent the strangeness of file names and misapplied keywords by letting users vote on whether or not an image is really what they were looking for. Search for "school bus", for example, and get some images of a micro-processor bus and you can flag them as not helpful to your search. Because thousands of users have come before you, analyzing the images, you won't often find misplaced images. Search results are divided into sorted and unsorted images, with the sorted images on top—sorted in this case means that users have verified that the images do in fact contain the thing you are looking for.
Sprixi currently pulls images from Flickr, OpenClipart.org, and from user uploads. Sprixi is a free service and requires no registration or login to use. [Lifehacker Annotation]
One of the frustrations of searching for anything on the internet, let alone images, is imprecise search results. If you've ever searched for something and found something completely different—usually because the file name or the associated keywords were strangely or inappropriately applied—then you know what we're talking about.
Sprixi helps circumvent the strangeness of file names and misapplied keywords by letting users vote on whether or not an image is really what they were looking for. Search for "school bus", for example, and get some images of a micro-processor bus and you can flag them as not helpful to your search. Because thousands of users have come before you, analyzing the images, you won't often find misplaced images. Search results are divided into sorted and unsorted images, with the sorted images on top—sorted in this case means that users have verified that the images do in fact contain the thing you are looking for.
Sprixi currently pulls images from Flickr, OpenClipart.org, and from user uploads. Sprixi is a free service and requires no registration or login to use. [Lifehacker Annotation]
Useful Resources
View all resources
Editor Favorites
- A List Apart
- HTML Validator Firefox Plugin
- Open Clip Art Library
- Core JavaScript Guide: Version 1.5
- Splashup
- XML Sitemaps Generator
- Clearspring Launchpad
- Text Fixer
Other Resources
- dTree
- CSS Menu Generator
- Amaya
- FreeStyle Menu
- CSS Tab Designer
- Create a multi-state image toolbar on your Web site with this JavaScript guide
- Search Engine Friendly Layouts
- Open Source Web Design (OSWD)
- Whats Its Color
- Regular Expression Tutorial: Learn How to Use and Get The Most out of Regular Expressions
- FastStone Capture
- PikiFX.com
- WPClipart
- LogoInstant
- LogoYes
- 99designs
- Sprixi
Links to Consider
Most of the time, we write PHP scripts with the idea that they will be run directly in a browser (HTTP). Occasionally, we want to run a script directly from the command line (e.g., in a SSH environment or via a cron job). Unfortunately, running these scripts from the command line can cause problems since most HTTP environment variables are either not available in the command line mode or are not what you might expect them to be. The most common problem this has caused for me is that when I want to include scripts using the
You can read more about Using PHP from the command line on the PHP site. While that page told me a lot of useful information about running scripts in command mode, it didn't actually tell me how to solve my problem of includes not functioning properly in command line mode. Of course, you could just use an absolute path to your include files, but this isn't a very flexible approach if you decide to change servers, etc. Finally, I did track down a useful piece of code which will do the trick. At the top of your script (or, at least, before any include or require statements) add:
and then make your include statements use paths relative to the script's directory location, e.g.,
which I presume you are probably already doing...
Since running a PHP script from the command line (php cli) doesn't change the directory to that of the script, your included files probably won't be found. The statement above will change the directory and thus your relative paths will function as you originally intended. One warning, however; if your included files further include other files you will probably still have problems so you need to add the command above to each file that has an
Now, I have another warning. As I mentioned at first, many global server environment variables are not available in the command line mode or are different than you might expect. You can find out which ones are available by using the following command line command:
One thing you can do to deal with this in a fairly easy way is to call your script with the relevant variable you care about. For example, say you want your script to access the
but that variable won't be available in command line mode. So, you can call the script like this:
The mydomain.com value will automatically be added to a command line environment variables array,
In this case, if the script is run in command line mode with the host variable passed it will run fine, but if it is called by a browser the
My final warning regards calling the script in command line mode. Notice that I used:
I believe that is fine for most server setups, but apparently, some servers will require you to specify the whole path to PHP, like:
You might also find the following tutorials useful:
include or require commands and I get path problems.You can read more about Using PHP from the command line on the PHP site. While that page told me a lot of useful information about running scripts in command mode, it didn't actually tell me how to solve my problem of includes not functioning properly in command line mode. Of course, you could just use an absolute path to your include files, but this isn't a very flexible approach if you decide to change servers, etc. Finally, I did track down a useful piece of code which will do the trick. At the top of your script (or, at least, before any include or require statements) add:
chdir(dirname(__FILE__));and then make your include statements use paths relative to the script's directory location, e.g.,
include("../includes/file.php"); which I presume you are probably already doing...
Since running a PHP script from the command line (php cli) doesn't change the directory to that of the script, your included files probably won't be found. The statement above will change the directory and thus your relative paths will function as you originally intended. One warning, however; if your included files further include other files you will probably still have problems so you need to add the command above to each file that has an
include or require statement.Now, I have another warning. As I mentioned at first, many global server environment variables are not available in the command line mode or are different than you might expect. You can find out which ones are available by using the following command line command:
php –iOne thing you can do to deal with this in a fairly easy way is to call your script with the relevant variable you care about. For example, say you want your script to access the
HTTP_HOST environment variable. In the regular script you might have:$host = $_SERVER['HTTP_HOST'];but that variable won't be available in command line mode. So, you can call the script like this:
php /path/to/your/script/scriptname mydomain.comThe mydomain.com value will automatically be added to a command line environment variables array,
$_SERVER['argv']. The first array value ($_SERVER['argv'][0]) will be the script name you are running and then the next values will be the variables you include in order. So you could change your script to the following:$host = $_SERVER['argv'][1];if (!$host) $host = $_SERVER['HTTP_HOST'];In this case, if the script is run in command line mode with the host variable passed it will run fine, but if it is called by a browser the
$_SERVER['argv'] won't exist and instead we can use our original global environment variable.My final warning regards calling the script in command line mode. Notice that I used:
php /path/to/your/script/scriptname mydomain.comI believe that is fine for most server setups, but apparently, some servers will require you to specify the whole path to PHP, like:
/usr/bin/php /path/to/your/script/scriptname mydomain.comYou might also find the following tutorials useful:
- PHP on the Command Line - Part 1 by Harry Fuecks
- PHP on the Command Line - Part 2 by Harry Fuecks
| Text Size: |
TrackBack URI
