Function: php-ts-mode-run-php-webserver

php-ts-mode-run-php-webserver is an autoloaded, interactive and byte-compiled function defined in php-ts-mode.el.gz.

Signature

(php-ts-mode-run-php-webserver &optional PORT HOSTNAME DOCUMENT-ROOT ROUTER-SCRIPT NUM-OF-WORKERS CONFIG)

Documentation

Run PHP built-in web server.

PORT: Port number of built-in web server, default php-ts-mode-ws-port. Prompt for the port if the default value is nil. HOSTNAME: Hostname or IP address of Built-in web server, default php-ts-mode-ws-hostname. Prompt for the hostname if the default value is nil. DOCUMENT-ROOT: Path to Document root, default php-ts-mode-ws-document-root. Prompt for the document-root if the default value is nil. ROUTER-SCRIPT: Path of the router PHP script, see https://www.php.net/manual/en/features.commandline.webserver.php NUM-OF-WORKERS: Before run the web server set the PHP_CLI_SERVER_WORKERS env variable useful for testing code against multiple simultaneous requests CONFIG: Alternative php.ini config, default php-ts-mode-php-config.

Interactively, when invoked with prefix argument, always prompt for PORT, HOSTNAME, DOCUMENT-ROOT, ROUTER-SCRIPT, NUM-OF-WORKERS and CONFIG.

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/php-ts-mode.el.gz
;;;###autoload
(defun php-ts-mode-run-php-webserver (&optional port
						hostname
						document-root
						router-script
						num-of-workers
						config)
  "Run PHP built-in web server.

PORT: Port number of built-in web server, default `php-ts-mode-ws-port'.
Prompt for the port if the default value is nil.
HOSTNAME: Hostname or IP address of Built-in web server,
default `php-ts-mode-ws-hostname'.  Prompt for the hostname if the
default value is nil.
DOCUMENT-ROOT: Path to Document root, default `php-ts-mode-ws-document-root'.
Prompt for the document-root if the default value is nil.
ROUTER-SCRIPT: Path of the router PHP script,
see `https://www.php.net/manual/en/features.commandline.webserver.php'
NUM-OF-WORKERS: Before run the web server set the
PHP_CLI_SERVER_WORKERS env variable useful for testing code against
multiple simultaneous requests
CONFIG: Alternative php.ini config, default `php-ts-mode-php-config'.

Interactively, when invoked with prefix argument, always prompt for
PORT, HOSTNAME, DOCUMENT-ROOT, ROUTER-SCRIPT, NUM-OF-WORKERS and
CONFIG."
  (interactive (when current-prefix-arg
		 (php-ts-mode--webserver-read-args)))
  (let* ((port (or
		port
		php-ts-mode-ws-port
		(php-ts-mode--webserver-read-args 'port)))
	 (hostname (or
		    hostname
		    php-ts-mode-ws-hostname
		    (php-ts-mode--webserver-read-args 'hostname)))
	 (document-root (or
			 document-root
			 php-ts-mode-ws-document-root
			 (php-ts-mode--webserver-read-args 'document-root)))
	 (config (or config
		     (when php-ts-mode-php-config
		       (expand-file-name php-ts-mode-php-config))))
	 (host (format "%s:%d" hostname port))
	 (name (format "PHP web server on: %s" host))
	 (buf-name (format "*%s*" name))
	 (args (delq
		nil
		(list "-S" host
		      "-t" document-root
		      (when config
			(format "-c %s" config))
		      router-script)))
	 (process-environment
	  (nconc (cond
		  (num-of-workers
		   (list
		    (format "PHP_CLI_SERVER_WORKERS=%d" num-of-workers)))
		  (php-ts-mode-ws-workers
		   (list
		    (format "PHP_CLI_SERVER_WORKERS=%d" php-ts-mode-ws-workers))))
		 process-environment)))
    (if (get-buffer buf-name)
	(message "Switch to already running web server into buffer %s" buf-name)
      (message "Run PHP built-in web server with args %s into buffer %s"
	       (string-join args " ")
	       buf-name)
      (apply #'make-comint name (php-ts-mode--executable) nil args))
    (funcall
     (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer)
     buf-name)))