What is the canonical way to determine commandline vs. http execution of a PHP script?

Use the php_sapi_name() function. if (php_sapi_name() == “cli”) { // In cli-mode } else { // Not in cli-mode } Here are some relevant notes from the docs: php_sapi_name — Returns the type of interface between web server and PHP Although not exhaustive, the possible return values include aolserver, apache, apache2filter, apache2handler, caudium, cgi (until … Read more

Execute and get the output of a shell command in node.js

This is the method I’m using in a project I am currently working on. var exec = require(‘child_process’).exec; function execute(command, callback){ exec(command, function(error, stdout, stderr){ callback(stdout); }); }; Example of retrieving a git user: module.exports.getGitUser = function(callback){ execute(“git config –global user.name”, function(name){ execute(“git config –global user.email”, function(email){ callback({ name: name.replace(“\n”, “”), email: email.replace(“\n”, “”) }); … Read more

How do I avoid typing “git” at the begining of every Git command?

You might want to try gitsh. From their readme: The gitsh program is an interactive shell for git. From within gitsh you can issue any git command, even using your local aliases and configuration. Git commands tend to come in groups. Avoid typing git over and over and over by running them in a dedicated … Read more

Delete node_modules folder recursively from a specified path using command line

Print out a list of directories to be deleted: find . -name ‘node_modules’ -type d -prune Delete directories from the current working directory: find . -name ‘node_modules’ -type d -prune -exec rm -rf ‘{}’ + Alternatively you can use trash (brew install trash) for staged deletion: find . -name node_modules -type d -prune -exec trash … Read more

Switch php versions on commandline ubuntu 16.04

Interactive switching mode sudo update-alternatives –config php sudo update-alternatives –config phar sudo update-alternatives –config phar.phar Manual Switching From PHP 5.6 => PHP 7.1 Default PHP 5.6 is set on your system and you need to switch to PHP 7.1. Apache: $ sudo a2dismod php5.6 $ sudo a2enmod php7.1 $ sudo service apache2 restart Command Line: … Read more