C Supervised PHP Modes of Use Primer Tutorial

C Supervised PHP Modes of Use Primer Tutorial

C Supervised PHP Modes of Use Primer Tutorial

Recently, with our tutorial, PHP Modes of Use Primer Tutorial as shown below, we talked about three modes of use or access for the use of PHP and today we encase all that thinking in a Mac OS X command line C program supervision framework. You’d expect that this is possible in a command line or Intranet environment where Linux or unix (or, for that matter, Windows command line … though the code here won’t work for this one) where C can have such a close relationship to the Linux or unix kernel, that it would be able the “run the whole show” as well as the shell commands themselves can. Today’s C has been compiled using the Xcode IDE for use with a Mac OS X operating system.

So that’s the supervisor above. Read, again, about “the supervised”, below …

PHP is a very flexible programming language. It is probably best known as a server-side language called by a web browser using the http transport layer (ie. web browsing, or “surfing the net”). Let’s list three modes of use of PHP below:

  1. Via http transport layer (ie. web browsing, or “surfing the net”) in an Internet mode of use (eg: HTTP://localhost:8888/in_tra_ter_net.php?SERVER_NAME=localhost) in address bar of a web browser
  2. Via curl in an Internet mode of use (eg. curl HTTP://localhost:8888/in_tra_ter_net.php?SERVER_NAME=localhost) at Linux or unix or Windows command line to default output (and you can redirect as required via > outfile or >> outfile or 2> errfile or 2>> errfile)
  3. Via command line PHP in Linux or unix or Windows command line in a command or Intranet mode of use (eg. php in_tra_ter_net.php SERVER_NAME=localhost) at a Linux or unix or Windows command line (where the PHP code has been placed, in our example (ie. it is not a URL, but is a file specification of your (Intranet) server)) to default output (or you can redirect as required via > outfile or >> outfile or 2> errfile or 2>> errfile)

Does it matter how the PHP is accessed? Well, yes, it does … sometimes, but not if the code is restricted to a particular mode of usage (but part of what this tutorial is about is to get across how flexible and powerful PHP can be). With the last option above, lots of $_SERVER[] variables are undefined, for example.

  1. $_SERVER[‘HTTP_COOKIE’] is defined, unlike with curl usage (this seems to be a possibility as a way to detect curl usage). Most $_SERVER[] variables are defined, but $argv[] array is not.
  2. $_SERVER[‘HTTP_COOKIE’] is undefined, but a lot of the rest of $_SERVER[] variables are as above.
  3. Lots of $_SERVER[] variables are undefined, with the exception of $_SERVER[‘SCRIPT_FILENAME’] which may help you with Intranet application usage. You cannot enter $_GET[] arguments (on the command line (ie. you will get a syntax error if you try)) so these are undefined, but $argv[] array can be used in that awkward way shown, so that $argv[1] can be arranged to be a lot like $_SERVER[‘QUERY_STRING’] (ie. the bits after ? in a URL).

So, maybe you have the one mode of use in mind, but you need to think a bit to support all the modes of use, if they are all to have a role with the PHP you write, because, despite these differences it is good to use $_SERVER[] and $_GET[] and $_POST[] and $_SESSION[] and $argv[] and whatever else in terms of variable information PHP offers in terms of attempting to write generic code.

Hope you get something out of today’s discussion of our Mac OS X MAMP Apache local Web server environment example (hence the HTTP://localhost:8888/ you see in the URLs above), but please bear in mind that there would be other modes of use once you think of other client HTML element ways of accessing PHP (all a lot like the “web browsing” of above) or other possibilities within PHP code itself via PHP commands exec and file_get_contents the latter of which can be very useful during Intranet usage where there is no curl available, perhaps. Instead of curl you could use wget as another approach.

You may want to see a live run (web browsing) here at the rjmprogramming.com.au domain of the supervised PHP (alone), or you may want to download the supervised PHP programming source code you could call in_tra_ter_net.php or you may want to download the supervisory main.c as you require.

A “stop press” to do with code above is that since the “queueing up” of this blog post a new posting is relevant, the recent PHP Modes of Use Follow Up Tutorial, and that to incorporate this posting’s improvements over PHP Modes of Use Primer Tutorial, you’d want to substitute all mentions of in_tra_ter_net with more_in_tra_ter_net in the code of main.c as above. The relevant changed PHP source code is more_in_tra_ter_net.php


Previous relevant PHP Modes of Use Primer Tutorial is shown below.

PHP Modes of Use Primer Tutorial

PHP Modes of Use Primer Tutorial

PHP is a very flexible programming language. It is probably best known as a server-side language called by a web browser using the http transport layer (ie. web browsing, or “surfing the net”). Let’s list three modes of use of PHP below:

  1. Via http transport layer (ie. web browsing, or “surfing the net”) in an Internet mode of use (eg: HTTP://localhost:8888/in_tra_ter_net.php?SERVER_NAME=localhost) in address bar of a web browser
  2. Via curl in an Internet mode of use (eg. curl HTTP://localhost:8888/in_tra_ter_net.php?SERVER_NAME=localhost) at Linux or unix or Windows command line to default output (and you can redirect as required via > outfile or >> outfile or 2> errfile or 2>> errfile)
  3. Via command line PHP in Linux or unix or Windows command line in a command or Intranet mode of use (eg. php in_tra_ter_net.php SERVER_NAME=localhost) at a Linux or unix or Windows command line (where the PHP code has been placed, in our example (ie. it is not a URL, but is a file specification of your (Intranet) server)) to default output (or you can redirect as required via > outfile or >> outfile or 2> errfile or 2>> errfile)

Does it matter how the PHP is accessed? Well, yes, it does … sometimes, but not if the code is restricted to a particular mode of usage (but part of what this tutorial is about is to get across how flexible and powerful PHP can be). With the last option above, lots of $_SERVER[] variables are undefined, for example.

  1. $_SERVER[‘HTTP_COOKIE’] is defined, unlike with curl usage (this seems to be a possibility as a way to detect curl usage). Most $_SERVER[] variables are defined, but $argv[] array is not.
  2. $_SERVER[‘HTTP_COOKIE’] is undefined, but a lot of the rest of $_SERVER[] variables are as above.
  3. Lots of $_SERVER[] variables are undefined, with the exception of $_SERVER[‘SCRIPT_FILENAME’] which may help you with Intranet application usage. You cannot enter $_GET[] arguments (on the command line (ie. you will get a syntax error if you try)) so these are undefined, but $argv[] array can be used in that awkward way shown, so that $argv[1] can be arranged to be a lot like $_SERVER[‘QUERY_STRING’] (ie. the bits after ? in a URL).

So, maybe you have the one mode of use in mind, but you need to think a bit to support all the modes of use, if they are all to have a role with the PHP you write, because, despite these differences it is good to use $_SERVER[] and $_GET[] and $_POST[] and $_SESSION[] and $argv[] and whatever else in terms of variable information PHP offers in terms of attempting to write generic code.

Hope you get something out of today’s discussion of our Mac OS X MAMP Apache local Web server environment example (hence the HTTP://localhost:8888/ you see in the URLs above), but please bear in mind that there would be other modes of use once you think of other client HTML element ways of accessing PHP (all a lot like the “web browsing” of above) or other possibilities within PHP code itself via PHP commands exec and file_get_contents the latter of which can be very useful during Intranet usage where there is no curl available, perhaps. Instead of curl you could use wget as another approach.

You may want to see a live run (web browsing) here at the rjmprogramming.com.au domain or you may want to download the PHP programming source code you could call in_tra_ter_net.php as you require.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>