The standard Run Level for a linux machine booting up in full GUI mode is Run Level 5. In my experience, the most common Run Level (other than 5 for standard boot up) is Run Level 3. The most common need for Run Level 3 is for debugging problems and installing graphic drivers.
If you want to specify a default Run Level other than 5, the option can be changed in your /etc/inittab as defined by the initdefault directive. Below is a table specifying the other various Run Levels and State properties. Note that it is important never to set your initdefault directive to Run Level 0 or 6.
| Run Level |
State |
| 0 |
halt (shutdown) system |
| 1 |
single user mode |
| 2 |
multi user with no network exported |
| 3 |
default full multi user console (text) only |
| 4 |
reserved for local use (and X-window) |
| 5 |
X-window full GUI mode |
| 6 |
reboot system |
Change Run Level After Boot Up
The easiest way to change the Run Level after the system has already been booted up is to open up the console and use init. There is an example below on how to change the Run Level to 3.
init 3
In addition, teleinit is an alternative to init and works in exactly the same manner.
telinit 3
Change Run Level on System Boot Up
If however your Linux machine is currently powered off and you would like to boot directly into an alternative Run Level, you can change the Run Level by accessing the linux startup boot menu (GRUB). Simply choose the desired kernel and add init 3 into the kernel string.
PHP applications that involve accessing stock symbol prices, changes, and additional details on a repeated basis can be easily obtained from Yahoo. The below url will open an excel spreadsheet. Simply replace XXX with a comma delimited list of stock ticker symbols.
http://finance.yahoo.com/d/quotes.csv?s=XXX&f=sl1d1t1c1ohgv&e=.csv
The resulting spreadsheet displays a row for each ticker with the following informations from columns A to I: symbol, last price, date, time, change, open, high, low, and volume. To incorporate the above url into PHP, follow the below script that handles one ticker. We will use Google (GOOG) as an example. The script will output the result from the spreadsheet into an html table.
<?php
$fp = fopen("http://finance.yahoo.com/d/quotes.csv?s=goog&f=sl1d1t1c1ohgv&e=.csv","r");
$data = fgetcsv($fp, 1000, ",")
?>
<table>
<tr><td>description</td><td>latest figure</td><tr>
&t;tr><td>symbol</td><td><?php echo $data[0] ?></td></tr>
<tr><td>last price</td><td><?php echo $data[1] ?></td></tr>
<tr><td>date</td><td><?php echo $data[2] ?></td></tr>
<tr><td>time</td><td><?php echo $data[3] ?></td></tr>
<tr><td>change</td><td><?php echo $data[4] ?></td></tr>
<tr><td>open</td><td><?php echo $data[5] ?></td></tr>
<tr><td>high</td><td><?php echo $data[6] ?></td></tr>
<tr><td>low</td><td><?php echo $data[7] ?></td></tr>
<tr><td>volume</td><td><?php echo $data[8] ?></td></tr>
</table>
<?php
fclose($fp);
?>
In the above script example, the fopen function opens the file to be read. Next, the fgetscv function moves cells from a CSV excel file into an array. The array can then be manipulated as necessary. Lastly, the fclose function closes the the open file.
Altering this code to handle multiple stock ticker symbols in one sheet would be possible, but would make this simple example a bit more complex. This script will however get you started with getting the stock information you need for your PHP web application.