Home >Backend Development >PHP Problem >Why doesn't php need to be compiled?

Why doesn't php need to be compiled?

(*-*)浩
(*-*)浩Original
2019-09-26 11:43:464150browse

Why doesn't php need to be compiled?

Although PHP does not need to be compiled, can it really be run after being written?

One of the major features of PHP is the scripting language. A script is usually interpreted and run instead of compiled.

PHP is an interpreted language. The PHP code is interpreted into opcode and then handed over to the Zend engine for execution. (Recommended learning: PHP programming from entry to proficiency)

Interpreted language: the program does not need to be compiled, the program is translated into machine language when it is run, and every time it is executed Translate every time.

Interpreted language

The source program is precompiled into an intermediate language before the program is run, and then the intermediate language is executed by the interpreter each time the interpreted language is executed Language programs need to be compiled once, so the running efficiency of interpreted language programs is usually low, and it cannot run independently from the interpreter. C#, PHP, Python, Java, etc. are all interpreted languages.

But can it really be run after writing? But no.

If PHP code wants to run, it must have a "mother" - the "PHP executable program" we compiled.

In Linux, this matrix may be placed in /usr/local/php/bin/php

How to run it?

1./usr/local/php/bin/php followed by a PHP file

2./usr/local/php/bin/php -r 'here Directly write the PHP code '

3. Create a file and write #!/usr/local/php/bin/php

on the first line so that you can identify whether the file is PHP to run (the file name does not have to end with .php)

Example:

$ vi god
#/usr/local/php/bin/php<?php
    echo &#39;hello world!&#39;.PHP_EOL;

The above is the detailed content of Why doesn't php need to be compiled?. 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