Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

Free AI exercises


PHP (more)



Server-side command-line

PHP runs on server.
Can access command-line to execute external programs on server-side. (e.g. Linux commands)


To find out if command-line is enabled

  1. Find where your php.ini file is (use phpinfo)
    See disabled functions:
    disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_so,pcntl_exec
    

  2. Or run a PHP test:
    // do these functions exist:
    if ( function_exists ('exec')       ) echo " exec "; 
    if ( function_exists ('passthru')   ) echo " passthru ";
    if ( function_exists ('shell_exec') ) echo " shell_exec ";
    if ( function_exists ('system')     ) echo " system ";
    
    // show value of the setting "disable_functions":
    $x = ini_get("disable_functions");
    echo " $x ";
    


If command-line disabled

Even if your sysadmin has disabled the command line, a lot of command-line functionality can be done without leaving PHP.
Listing files, reading and writing files, searching files, and even wildcard matching:
  

Example

system ( "ls -l (dir)" );



Make HTTP requests

PHP runs on server. Can make HTTP requests to other sites. Request comes from server, not from client.



Include other PHP page




Run PHP on command-line

Running PHP on the command-line. Stand-alone PHP scripts.
i.e. Not running it from a web page.
You can use PHP as a general purpose offline programming language (not on a web server).
Note this is a different concept to a PHP web page accessing the command-line.




ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.      New 250 G VPS server.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.