php:php
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
php:php [2015/08/04 07:57] – [config debug mode in PHP] admin | php:php [2022/10/29 16:15] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 4: | Line 4: | ||
* Eclipse pdt: [[php: | * Eclipse pdt: [[php: | ||
===== Create PHP simple code and run ===== | ===== Create PHP simple code and run ===== | ||
- | ==== create | + | ==== Create |
<code php> | <code php> | ||
<?php | <?php | ||
Line 10: | Line 10: | ||
?> | ?> | ||
</ | </ | ||
- | ==== create | + | ==== Create |
<code php> | <code php> | ||
<?php | <?php | ||
Line 16: | Line 16: | ||
?> | ?> | ||
</ | </ | ||
- | ==== run PHP code ==== | + | ==== Run PHP code ==== |
* linux: <code bash> | * linux: <code bash> | ||
php helloworld.php | php helloworld.php | ||
Line 24: | Line 24: | ||
</ | </ | ||
===== How to debug in PHP and Javascript ===== | ===== How to debug in PHP and Javascript ===== | ||
- | ==== config | + | ==== Config |
check http:// | check http:// | ||
error_log = / | error_log = / | ||
+ | </ | ||
+ | chown www.www / | ||
</ | </ | ||
Config turn on/off debug log in **php**: | Config turn on/off debug log in **php**: | ||
Line 41: | Line 43: | ||
track_errors = On | track_errors = On | ||
</ | </ | ||
- | Config turn on debug log in **php-fpm**: | + | * Explain config: |
- | < | + | Config turn on debug log in **ngix with php-fpm |
+ | * in php-fpm.conf< | ||
[global] | [global] | ||
error_log = / | error_log = / | ||
Line 48: | Line 51: | ||
[www] | [www] | ||
catch_workers_output = yes | catch_workers_output = yes | ||
+ | </ | ||
+ | * in php.ini:< | ||
+ | display_errors = On ⇒ Allow display debug information in front end | ||
</ | </ | ||
Config turn on/off log in httpd: | Config turn on/off log in httpd: | ||
Line 64: | Line 70: | ||
LogLevel error | LogLevel error | ||
</ | </ | ||
- | ==== config | + | ==== Config |
* in nginx< | * in nginx< | ||
###demo.vn | ###demo.vn | ||
Line 107: | Line 113: | ||
</ | </ | ||
</ | </ | ||
- | ==== debug with php code ==== | + | ==== Debug with php code ==== |
* Debug with print< | * Debug with print< | ||
print(variable_name) | print(variable_name) | ||
Line 125: | Line 131: | ||
?> | ?> | ||
</ | </ | ||
- | ==== debug with xdebug ==== | + | ==== Debug with xdebug ==== |
Refer: [[php: | Refer: [[php: | ||
- | ==== Query log of mysql server ==== | + | |
- | [windows] | + | |
- | log = " | + | |
- | [linux] | + | |
- | [mysqld] | + | |
- | log=/ | + | |
- | <code bash> | + | |
- | touch / | + | |
- | chown mysql.mysql / | + | |
- | SET GLOBAL general_log = ' | + | |
- | / | + | |
- | </ | + | |
==== Debug with Javascript ==== | ==== Debug with Javascript ==== | ||
* Debug with Internet Explorer: Turn on Debug Mode in Internet Options for debugging code javascript error | * Debug with Internet Explorer: Turn on Debug Mode in Internet Options for debugging code javascript error | ||
* Debug in Chrome: Using Developer Tools for debugging Javascript with break points | * Debug in Chrome: Using Developer Tools for debugging Javascript with break points | ||
+ | ===== PHPUnit ===== | ||
+ | refer: https:// | ||
+ | ==== Install PHPUnit ==== | ||
+ | * Install as binary< | ||
+ | wget -O phpunit https:// | ||
+ | chmod +x phpunit | ||
+ | ./phpunit --version | ||
+ | </ | ||
+ | * Install with composer:< | ||
+ | composer require --dev phpunit/ | ||
+ | ./ | ||
+ | </ | ||
+ | ==== Run PHPUnit ==== | ||
+ | ===== PHP Slow Log Config ===== | ||
+ | ==== Config Slow Log in php-fpm ==== | ||
+ | < | ||
+ | request_slowlog_timeout = 5s | ||
+ | slowlog = / | ||
+ | </ | ||
+ | ==== Config Slow Log for php ==== | ||
===== Basic Syntaxs ===== | ===== Basic Syntaxs ===== | ||
==== PHP tags ==== | ==== PHP tags ==== | ||
Line 332: | Line 347: | ||
if(!mysql_connect(" | if(!mysql_connect(" | ||
die(" | die(" | ||
- | </ | + | </ |
+ | ==== PHP mysql ==== | ||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | </ | ||
+ | ==== PHP mysqli ==== | ||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | </ | ||
+ | ==== Convert from mysql to mysqli ==== | ||
+ | Using tool: https:// | ||
+ | <code bash> | ||
+ | php MySQLConverterTool-master/ | ||
+ | </ | ||
+ | And Modify some missing in tool:< | ||
+ | mysqli_connect(" | ||
+ | </ | ||
+ | => mysqli_connect(" | ||
+ | </ | ||
+ | ===== PHP curl ===== | ||
+ | <code php> | ||
+ | <?php | ||
+ | function curl_post($url, | ||
+ | { | ||
+ | try{ | ||
+ | $ch = curl_init(); | ||
+ | if ($ch === false) { | ||
+ | throw new Exception(' | ||
+ | } | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | curl_setopt($ch, | ||
+ | $data = curl_exec($ch); | ||
+ | if ($data === false) { | ||
+ | throw new Exception(curl_error($ch), | ||
+ | } | ||
+ | curl_close($ch); | ||
+ | }catch(Exception $e){ | ||
+ | echo "Curl Error: " . $e-> | ||
+ | } | ||
+ | if($data) | ||
+ | return $data; | ||
+ | else | ||
+ | return false; | ||
+ | } | ||
+ | </ |
php/php.1438675061.txt.gz · Last modified: 2022/10/29 16:15 (external edit)