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)

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.

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

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)
  "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.

Interactively, when invoked with prefix argument, always prompt
for PORT, HOSTNAME, DOCUMENT-ROOT and ROUTER-SCRIPT."
  (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)))
         (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
                      router-script)))
         (process-environment
          (cons (cond
                 (num-of-workers (format "PHP_CLI_SERVER_WORKERS=%d" num-of-workers))
                 (php-ts-mode-ws-workers (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)))