# PHP AOT Compiler Quick Start Guide ## ๐Ÿš€ 5-Minute Quick Start This guide will help you get started with the PHP AOT compiler within 5 minutes. --- ## ๐Ÿ“ฆ Prerequisites ### System Requirements - **Operating System**: Linux (Ubuntu 20.04+ recommended) - **PHP Version**: PHP 8.0+ - **Compiler**: GCC 9.0+ or Clang 10.0+ - **Memory**: at least 2GB RAM - **Disk Space**: at least 500MB ### Installing Dependencies ```bash # Ubuntu/Debian sudo apt-get update sudo apt-get install -y build-essential php-cli php-dev clang-format # CentOS/RHEL sudo yum install -y gcc gcc-c++ php php-devel clang-tools-extra ``` --- ## ๐Ÿ”ง Installation Steps ### 1. Clone the Project ```bash git clone https://github.com/your-org/php-aot-compiler.git cd php-aot-compiler ``` ### 2. Install Composer Dependencies ```bash composer install ``` ### 3. Verify Installation ```bash php bin/tpc.php --help ``` If you see the help information, the installation was successful! --- ## ๐ŸŽฏ Basic Usage ### Example Project Structure Suppose we have a simple PHP project: ``` my-project/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ Calculator.php โ”‚ โ””โ”€โ”€ main.php ``` **Calculator.php**: ```php add(5, 3) . "\n"; echo "4 * 7 = " . $calc->multiply(4, 7) . "\n"; } ``` --- ## ๐Ÿ“ Compilation Modes ### Mode One: Binary Executable (recommended for beginners) #### Compilation Command ```bash php bin/tpc.php my-project/src/ -o my-app ``` #### Running the Program ```bash ./my-app ``` #### Output ``` 5 + 3 = 8 4 * 7 = 28 ``` โœ… **Advantages**: - Runs standalone without a PHP environment - Simple deployment - Better performance โš ๏ธ **Note**: a `main()` function is required --- ### Mode Two: PHP Extension #### Compilation Command ```bash php bin/tpc.php my-project/src/ --mode=ext -o calculator ``` #### Installing the Extension ```bash # Copy the .so file to the PHP extension directory sudo cp calculator.so $(php-config --extension-dir)/ # Add to php.ini echo "extension=calculator" | sudo tee /etc/php/8.1/cli/conf.d/30-calculator.ini ``` #### Using the Extension ```bash php -m | grep calculator # verify the extension is loaded ``` โœ… **Advantages**: - Integrates with existing PHP projects - Can be used in php-fpm - Suitable for web applications โš ๏ธ **Note**: no `main()` function is needed --- ## ๐ŸŽจ Code Conventions ### โœ… Correct Code Structure ```php doSomething(); echo helperFunction(); echo MY_CONSTANT; } ``` ### โŒ Incorrect Code Structure ```php