Как проверить работает ли php
Перейти к содержимому

Как проверить работает ли php

  • автор:

�� Как проверить PHP-скрипт

PHP – широко используемый скриптовый язык общего назначения, который особенно подходит для веб-разработки и может быть встроен в HTML.

PHP работает во всех основных операционных системах, от вариантов Unix, включая Linux, FreeBSD, Ubuntu, Debian и Solaris, до Windows и Mac OS X.

Его можно использовать со всеми ведущими веб-серверами, включая серверы Apache, Nginx, OpenBSD и многие другие. ; даже облачные среды, такие как Azure и Amazon.

Ниже приведены некоторые способы тестирования скриптов PHP.

Тестирование простого PHP-скрипта

1. Создайте файл со следующим содержимым.

Дайте файлу имя, например, myphpInfo.php:

2. Скопируйте файл в каталог DocumentRoot вашего веб-сервера, например – /var/www/html.

У вас может быть другой каталог DocumentRoot в зависимости от того, какой веб-сервер вы используете и какая конфигурация применяется.

3. Измените права на 755 (только для Linux):

Тестирование PHP-скрипта, который использует соединения с базой данных

1. Создайте файл со следующим содержимым. Дайте файлу имя, например phpdbchk.php:

2. Установите для ORACLE_HOME и TNS_ADMIN правильные значения.

3. Скопируйте файл в каталог DocumentRoot.

4. Измените переменные $username, $password, $database_hostname, $database_port, $database_sid и $database_srvc, необходимые для тестовой системы.

How to check if a php script is still running

I have a PHP script that listens on a queue. Theoretically, it’s never supposed to die. Is there something to check if it’s still running? Something like Ruby’s God ( http://god.rubyforge.org/ ) for PHP ?

God is language agnostic but it would be nice to have a solution that works on windows as well.

Alive to die - Anant's user avatar

13 Answers 13

I had the same issue — wanting to check if a script is running. So I came up with this and I run it as a cron job. It grabs the running processes as an array and cycles though each line and checks for the file name. Seems to work fine. Replace #user# with your script user.

In linux run ps as follows:

You could then do in a php script:

The above code lists all php processes running in full, then checks to see if «my_script.php» is in the list of running processes, if not it runs the process and does not wait for the process to terminate to carry on doing what it was doing.

Just append a second command after the script. When/if it stops, the second command is invoked. Eg.:

Technically, this invokes the mailer right away, but only completes the command when the php script ends. Doing this captures the output of the php-script and includes in the mail body, which can be useful for debugging what caused the script to halt.

troelskn's user avatar

Simple bash script

Not for windows, but.

I’ve got a couple of long-running PHP scripts, that have a shell script wrapping it. You can optionally return a value from the script that will be checked in the shell-script to exit, restart immediately, or sleep for a few seconds -and then restart.

Here’s a simple one that just keeps running the PHP script till it’s manually stopped.

The «exec $0» restarts the script, without creating a sub-process that will have to unravel later (and take up resources in the meantime). This bash script wraps a mail-sender, so it’s not a problem if it exits and pauses for a moment.

How to test a PHP script

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. PHP runs on all major operating systems, from Unix variants including Linux, FreeBSD, Ubuntu, Debian, and Solaris to Windows and Mac OS X. It can be used with all leading web servers, including Apache, Nginx, OpenBSD servers to name a few; even cloud environments like Azure and Amazon are on the rise.

Below are some of the ways in which a PHP script can be tested.

Testing Simple PHP Script

1. Create a file with the following contents. Give the file a name such as myphpInfo.php:

2. Copy the file to the your webservers DocumentRoot directory, for example – /var/www/html. You may have a different DocumentRoot directory depending on which webserver you are using and the configuration done for it.

3. Change the permissions to 755 (Linux only):

4. Call the file from a browser:

Testing a PHP Script that uses Database Connections

1. Create a file with the following contents. Give the file a name such as phpdbchk.php:

2. Set ORACLE_HOME and TNS_ADMIN to the proper values.

3. Copy the file to the DocumentRoot directory.

4. Modify the variables $username, $password, $database_hostname, $database_port, $database_sid and $database_srvc as necessary for the test system

PHP syntax checker

PHP error checker allows to check your PHP code syntax, and find PHP errors easily and quickly. This PHP code checker tool highlights and goes to line with a syntax error.

You can check syntax for PHP 5, PHP 7 and PHP 8 🙂

To check your code, you must copy and paste, drag and drop a PHP file or directly type in the «PHP code» online editor below, and click on «Check PHP syntax» button.

You can see the user guide to help you to use this php checker tool.

User guide

  • First, Drag and drop your PHP file or copy / paste your PHP text directly into the editor above.
  • Finally, you must click on «Check PHP syntax» button to display if there is an syntax error in your code.

PHP code checker tool

PHP is a server-side scripting language, but can also be used as a general-purpose programming language.

PHP error checker tool allows to find syntax errors (lint). You can test your PHP code online directly in your browser.

If a syntax error is detected, then the line in error is highlighted, and it jumps to it to save time (no need to search the line).

It can be useful to make online test to save time (deployment . ).

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *