|
Replacing Perl Scripts with PHP Scripts
Jayesh Jain
Introduction
With the introduction of version 4.2, PHP has started supporting a new SAPI (Server Application Programming Interface) called CLI (Command Line Interface). This facility was introduced to help developers create small shell applications (scripts) with PHP. So, now you can kiss Perl goodbye forever.
The CLI SAPI was released for the first time with PHP 4.2.0, but was still experimental back then and had to be explicitly enabled with --enable-cli when running ./configure. With PHP 4.3.0 the CLI SAPI will no longer be experimental and therefore will always be built and installed as the php (called php.exe on Windows) binary.
What is PHP Shell Scripts?
Normally shells are interactive, but not always. It means the shell will accept commands from you through keyboard and execute them. But instead of issuing commands one by one we can store this sequence of commands into a text file and tell the PHP to execute this text file instead of entering the commands. This is known as PHP shell scripting.
A PHP Shell script is just like batch file is MS-DOS but has more power than the MS-DOS batch file, thanks to PHP.
Why Write Shell Scripts?
- Shell scripts can take input from a user or a file and output them to the screen.
- Useful to create our own commands/application.
- Don't have to reinvent the wheel.
- To automate some day to day tasks.
In this tutorial we shall learn how to use PHP's CLI feature to interpret shell scripts, we assume that you have fair understanding of PHP and that PHP is installed and working properly on your computer, you can have PHP installed on Linux or Windows (the examples in this tutorial are demonstrated with PHP installed under Windows but they should work the same on Linux machine)
[ Next Page ]
| Comments: | ||
| Thanks | Jeremy | 08/13/07 12:14 |
| ±â³×½ººÏ µµÀü, 100¹è »¡¶óÁö°í ½¬¿öÁø ¿µ¾î¿ø¸® | ÀÌÈÆ±â | 11/16/05 00:54 |
| Ä«/µå/ºú!ÀÌ·¸°Ô/ÇØ°áÇϼ¼¿ä | ±èÁø¼÷ | 03/23/05 09:52 |
| Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä! | ÀÌÇýÁø | 12/07/04 11:23 |
| ½Å.¿ë.ºÒ.·®.ÀÚ/´çÀÏ500/´ë.Ãâ.ºñ.¹ý | ÀÌÈñÁø | 12/06/04 02:33 |
| Ä«,µå,¿¬,ü,ÀÚ/¿¹.Á¤.ÀÚ ´ë,Ãâ 100-1000¸¸¿ø | ÀÌ´ÙÇö | 12/05/04 10:49 |
| ´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ý | ÇѰæ¿í | 12/05/04 03:01 |
| ½Å.¿ë.ºÒ.·®/Ä«.µå.¿¬.ü/´ë.Ãâ/È¥ÀÚ/ÇØ.°áÇÏ´Â/¹æ.¹ý | ±èÇö¼ | 11/28/04 03:49 |
| ½Å.¿ë.ºÒ.·®.ÀÚ/´çÀÏ500/´ë.Ãâ.ºñ.¹ý | ÀÌÈñÁø | 11/27/04 23:24 |
| ´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ý | ÇѰæ¹Î | 11/23/04 20:43 |
| Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä! | ÀÌÁ¤¿¬ | 11/18/04 20:52 |
| Ä«.µå.±ø.¾È.ÇÏ.°í.µ·.¸¸.µé.¾î.¾².´Â.ºñ.¹ý | ÀÌÈñÁø | 11/15/04 12:57 |
| Need Help | Manoj Mitra | 11/13/04 05:15 |
| php script to validate mobile number and emai | vijay | 07/01/04 16:47 |
| ´ëÃâ °ÅÀý½Ã 100%µÇ°ÔÇÏ´Â ¹æ¹ý(Çʵ¶)!!! | ¼Û´ÙÈñ | 01/22/04 06:47 |
| ´ëÃâ °ÅÀý½Ã µÇ°Ô ÇÏ´Â ¹æ¹ý!!! | ¼ÇöÈñ | 01/07/04 09:04 |
| ½Å¿ëºÒ·®/Ä«µå¿¬Ã¼/È¥ÀÚÇØ°áÇÏ´Â ¹æ¹ý!!(Çʵ¶) | µµ¿ì¹Ì | 10/04/03 04:04 |
| Can't start it | Magnus Bergmark | 04/28/03 12:00 |
| RE: But why? | Clay Neudeck | 03/14/03 18:52 |
| But why? | J Hilton | 02/19/03 13:12 |
| Important: CGI != CLI... | philip olson | 12/16/02 13:59 |
| RE: Can't reaplce Perl totally | Tom | 12/13/02 11:02 |
| RE: Daemon? | Jason | 12/03/02 10:35 |
| Daemon? | Spot | 11/28/02 02:31 |
| Some points | Kjartan Mannes | 11/26/02 09:40 |
| RE: CLI new? | Kjartan Mannes | 11/26/02 09:02 |
| RE: Excutable PHP in Unix System | Jason | 11/25/02 09:10 |
| Wondeful Article | Raj Kambli | 11/22/02 17:47 |
| RE: .exe incoming ;D | Jason | 11/21/02 10:08 |
| Excutable PHP in Unix System | Afif | 11/21/02 03:19 |
| Seriously underrated use of PHP | S Clark | 11/20/02 13:23 |
| RE: Great article | Dario Fumagalli | 11/19/02 10:14 |
| RE: Great article | epplestun | 11/19/02 06:19 |
| Very good | epplestun | 11/19/02 06:18 |
| RE: Great article | epplestun | 11/19/02 06:05 |
| .exe incoming ;D | Ripman | 11/18/02 16:33 |
| ummm .... | Anonymouse | 11/18/02 10:17 |
| executable | R. Vermeersch | 11/16/02 15:19 |
| Can't reaplce Perl totally | Bahwi | 11/15/02 15:52 |
| RE: Great article | BDKR | 11/15/02 15:38 |
| RE: Great article | Jayesh Jain | 11/13/02 17:24 |
| CLI new? | Steve Werby | 11/13/02 17:04 |
| Great article | N. Elsten | 11/12/02 11:09 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


