Home  >  Article  >  Backend Development  >  How to Execute External Programs with PHP with User Interface in a Controlled Intranet Environment?

How to Execute External Programs with PHP with User Interface in a Controlled Intranet Environment?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-21 08:20:03950browse

How to Execute External Programs with PHP with User Interface in a Controlled Intranet Environment?

Starting External Programs with PHP: Addressing Issues with System and Exec

In a controlled intranet environment, executing external programs from a PHP application can be a challenge. While commands like system and exec can launch processes, they face difficulties handling programs with a visible user interface.

The Problem:

The user is able to start programs that operate silently (e.g., "echo hello > hello.txt"). However, attempts to launch programs with a graphical user interface (e.g., "explorer") result in no action.

The Solution:

To resolve this issue, it's necessary to allow the Apache service running the PHP script to interact with the desktop:

  1. Open the Services control panel (services.msc) on the Windows XP machine.
  2. Locate the Apache service (e.g., "wampapache") and open its properties.
  3. Go to the "Log On" tab and select "Allow service to interact with Desktop."
  4. Stop and restart the Apache service.

Code Snippets:

After making these changes, you can now launch GUI programs from PHP using pclose and system:

Non-Blocking:

<code class="php">pclose(popen("start /B notepad.exe", "r"));</code>

Blocking:

<code class="php">system('start notepad.exe');</code>

Note:

This solution is tested on Windows XP and may not work on other Windows versions.

The above is the detailed content of How to Execute External Programs with PHP with User Interface in a Controlled Intranet Environment?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn