PHP

来自夜航船
跳到导航 跳到搜索

PHP is a popular general-purpose scripting language that is especially suited to web development

Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.

自 1994 年 Rasmus Lerdorf 创建 PHP 以来, PHP 语言经历了激烈的演进。虽然第一版是一个简单的一人开发的 CGI 程序,Rasmus Lerdorf、Andi Gutmans 和 Zeev Suraski 加入了该语言的第三个版本的开发,并根本性重新设计。从那之后, PHP 开发组也创建并发展起来。

PHP

趣味应用:https://www.photo2text.com/

开发者:Laruence

官方手册:http://php.net/manual/zh/

Resin Quercus:http://dev.christen.cn/date.php (3.1.x)

安装

安装依赖:

apt-get install libxml2-dev
apt-get install libpng12-dev
apt-get install libfreetype6-dev
apt-get install libjpeg-dev
apt-get install libcurl3-openssl-dev
apt-get install libcurl4-gnutls-dev
apt-get install libbz2-dev
apt-get install libxpm-dev
apt-get install libt1-dev
apt-get install libmcrypt-dev
apt-get install libmysql++-dev
apt-get install libxslt1-dev
apt-get install openssl

编译安装:

$ cd /opt/software/
$ wget http://cn2.php.net/get/php-5.6.35.tar.gz/from/this/mirror
$ mv mirror php-5.6.35.tar.gz
$ tar -zxvf php-5.6.35.tar.gz
$ cd php-5.6.35

$ ./configure --prefix=/opt/php --with-config-file-path=/opt/php/lib --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl-dir=/usr --with-openssl --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli

$ make && make install

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /opt/php/lib/php/extensions/no-debug-non-zts-20131226/
Installing PHP CLI binary:        /opt/php/bin/
Installing PHP CLI man page:      /opt/php/php/man/man1/
Installing PHP FPM binary:        /opt/php/sbin/
Installing PHP FPM config:        /opt/php/etc/
Installing PHP FPM man page:      /opt/php/php/man/man8/
Installing PHP FPM status page:   /opt/php/php/php/fpm/
Installing PHP CGI binary:        /opt/php/bin/
Installing PHP CGI man page:      /opt/php/php/man/man1/
Installing build environment:     /opt/php/lib/php/build/
Installing header files:           /opt/php/include/php/
Installing helper programs:       /opt/php/bin/
  program: phpize
  program: php-config
Installing man pages:             /opt/php/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /opt/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.2
[PEAR] PEAR           - installed: 1.10.5
Wrote PEAR system config file at: /opt/php/etc/pear.conf
You may want to add: /opt/php/lib/php to your php.ini include_path
/opt/software/php-5.6.35/build/shtool install -c ext/phar/phar.phar /opt/php/bin
ln -s -f phar.phar /opt/php/bin/phar
Installing PDO headers:           /opt/php/include/php/ext/pdo/

配置PHP:

$ ln -s /opt/php/bin/php /usr/bin/php

$ cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf

$ groupadd www-data
$ useradd -g www-data -s /sbin/nologin -M www-data

user = www-data
group = www-data
listen = 127.0.0.1:6060

$ /usr/local/sbin/php-fpm # 启动PHP

$ /opt/php/bin/php-config --configure-options

$ find /opt/php/ -name 'php.ini'

直接编译安装PHP之后,是没有php.ini的,我们可以从解压缩后的目录copy到/opt/php/lib,然后进行配置生效。

配置文件:

$ cd /opt/software/php-5.6.35/
$ cp php.ini-development /opt/php/lib/php.ini

upload_max_filesize = 10M

注册服务:

$ cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
$ chmod +x /etc/init.d/php-fpm

$ lsof -i:6060
COMMAND  PID     USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
php-fpm 3695     root    7u  IPv4 110725866      0t0  TCP localhost:6060 (LISTEN)
php-fpm 3696 www-data    0u  IPv4 110725866      0t0  TCP localhost:6060 (LISTEN)
php-fpm 3697 www-data    0u  IPv4 110725866      0t0  TCP localhost:6060 (LISTEN)
kill -9 3695
kill -9 3696
kill -9 3697

$ service php-fpm status
php-fpm is stopped
$ service php-fpm start
Starting php-fpm  done
$ service php-fpm status
php-fpm (pid 4952) is running...
$ lsof -i:6060          
COMMAND  PID     USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
php-fpm 4952     root    7u  IPv4 110775871      0t0  TCP localhost:6060 (LISTEN)
php-fpm 4953 www-data    0u  IPv4 110775871      0t0  TCP localhost:6060 (LISTEN)
php-fpm 4954 www-data    0u  IPv4 110775871      0t0  TCP localhost:6060 (LISTEN)

应用

Syntax

Comments

三种注释方法

<!DOCTYPE html>
<html>
<body>

<?php
// 这是单行注释

# 这也是单行注释

/*
这是多行注释块
它横跨了
多行
*/
?>

</body>
</html>

文件头部注释

/**
*这是一个什么文件
*
*此文件程序用来做什么的(详细说明,可选。)。
* @author      richard<e421083458@163.com>
* @version     $Id$
* @since        1.0
*/

函数头部注释

/**
* some_func 
* 函数的含义说明
*
* @access public
* @param mixed $arg1 参数一的说明
* @param mixed $arg2 参数二的说明
* @param mixed $mixed 这是一个混合类型
* @since 1.0
* @return array
*/
public function thisIsFunction($string, $integer, $mixed) {return array();}

类注释

/**
* 类的介绍
*
* 类的详细介绍(可选。)。
* @author         richard<e421083458@163.com>
* @since          1.0
*/
class Test {}

程序代码注释,注释的原则是将问题解释清楚,并不是越多越好

/* 生成配置文件、数据文件。*/

$this->setConfig();
$this->createConfigFile();  // 创建配置文件
$this->clearCache();         // 清除缓存文件
$this->createDataFiles();   // 生成数据文件
$this->prepareProxys();
$this->restart();

Function

Types

Variables

疑问

处理图片时报 Allowed memory size of 134217728 bytes exhausted 错误,因为PHP默认内存限制是128M,所以需要修改php.ini文件。

查找到

memory_limit = 128M

这一行,将128M改大点,我这里直接是改成了256M。

延伸阅读: