PHP __halt_compiler()

PHP 在使用__halt_compiler(); 后面的东西将不进行编译.

Posted in PHP | Leave a comment

Drupal 7 rewrite settings.php

  1. /**
  2.  * Form callback.
  3.  *
  4.  * @param $form
  5.  * @param $form_state
  6.  */
  7. function myform_submit(&$form, &$form_state) {
  8.  
  9.   global $databases;
  10.  
  11.   // Update settings.php.
  12.   $inputs = $form_state['input'];
  13.  
  14.   require_once DRUPAL_ROOT . '/includes/install.inc';
  15.  
  16.   $settings['databases'] = array(
  17.     'value'    => array('default' => array(
  18.       'default' => $databases['default']['default'],
  19.       'odbc' => array (
  20.         'database' => $inputs['olm_mart_db_name'],
  21.         'username' => $inputs['olm_mart_db_user'],
  22.         'password' => $inputs['olm_mart_db_pass']['pass1'],
  23.         'host' => $inputs['olm_mart_db_host'],
  24.         'port' => $inputs['olm_mart_db_port'],
  25.         'driver' => 'odbc',
  26.         'prefix' => '',
  27.       ),
  28.     )),
  29.     'required' => TRUE,
  30.   );
  31.  
  32.   //  $settings['drupal_hash_salt'] = array(
  33.   //    'value'    => drupal_random_key(),
  34.   //    'required' => TRUE,
  35.   //  );
  36.   drupal_rewrite_settings($settings);
  37. }
Posted in Drupal | Leave a comment

Mac install vagrant

  1. $brew cask install virtualbox
  2. $brew cask install vagrant
  3. $brew cask install vagrant-manager

https://puphpet.com/#create

https://laravel.com/docs/5.3/homestead

Posted in 其它 | Leave a comment

Docker configuration nginx,php7,mysql

Download php7, mysql, nginx

  1. $ docker pull php:7fpmalpine
  2. $ docker pull nginx
  3. $ docker pull mysql

Run php

在这里必须挂载目录到php-fpm, nginx不会直接执行,它检测到php文件,会把php文件的路径发到php-fpm去,php-fpm再依据nginx发过来的路径找到代码并执行啊。

  1. $ docker run it rm name xphp link xmysql:xmysql v /Users/zhouitpro/www/docker_web:/usr/share/nginx/html php:7fpmalpine
  2. # –link xmysql:xmysql 映射mysql

Install php ext

# 安装pdo_mysql
$ docker exec -it run xphp bash
Docker# docker-php-ext-install pdo_mysql
Docker# docker-php-ext-enable pdo_mysql

Run Nginx

nginx config file

server {
    listen       80;
    server_name  localhost;
    root /usr/share/nginx/html/;
    location ~ \.php$ {
        fastcgi_pass xphp:9000; # 这里对应上面的php-fpm别名, php-fpm端口默认是9000
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    location ~ /\.ht {
        deny  all;
    }
}
  1. $ docker run it rm  link xphp:xphp v /Users/zhouitpro/www/docker_web:/usr/share/nginx/html  v /Users/zhouitpro/www/docker/site.conf:/etc/nginx/conf.d/default.conf p 9090:80  nginx
  2.  
  3. # -p 是转发端口 外部的 9090对应nginx提供的80端口
  4. # –link 是映射上面的 php-fpm
  5. # -v 是映射本地的web目录到nginx的www目录,和配置文件

Mysql

$ docker run -it --rm --name xmysql -e MYSQL_ROOT_PASSWORD=root mysql
Posted in Docker | Leave a comment

HHVM

hhvm

$ brew install hhvm

安装Supervisord, 用于监控Supervisord并且可以自动重启hhvm当hhvm崩溃的时候

$ sudo easy_install supervisor
$ mkdir -p /usr/local/etc/supervisor.d/
Posted in PHP | Leave a comment

Capistrano 自动部署

Install

  1. $ gem install capistrano
  1. $ cap install #初始化
  2. $ cap production deploy #部署到在线
  3. $ cap production deploy:rollback #回滚

config/deploy.rb
:application 应用名
:repo_url 远程仓库地址
:deploy_to 服务器目录

其它工具:
Deployer
Magallanes
Rocketeer

Posted in 其它 | Leave a comment

PHP 错误处理

  1. /**
  2.  * Error.
  3.  *
  4.  * 3rd comonpent:
  5.  *   filp/whoops
  6.  *   monolog/monolog error log
  7.  */
  8.  
  9. set_error_handler(function($errno, $errstr, $errfile, $errline, $errorcontext) {
  10.  
  11.   if(!(error_reporting() & $errno)) {
  12.     return;
  13.   }
  14.  
  15.   throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
  16. });
  17.  
  18.  
  19. var_dump($test);
Posted in PHP | Leave a comment

PHP DatePeriod 周期

  1. /**
  2.  * DatePeriod
  3.  *
  4.  * 3rd component: https://github.com/briannesbitt/Carbon
  5.  */
  6.  
  7.  
  8. /**
  9.  * DateInterval 表示到下一个周期的时间间隔.
  10.  *
  11.  * 2W表示两周.
  12.  */
  13. $interval = new DateInterval('P2W');
  14. $start = new DateTime();
  15.  
  16. $periods = new DatePeriod($start, $interval, 3, DatePeriod::EXCLUDE_START_DATE);
  17.  
  18. foreach($periods as $nextDateTime) {
  19.   var_dump($nextDateTime->format('Y-m-d'));
  20. }
Posted in PHP | Leave a comment

PHP Password Hashing

/**
* PHP Password
*
* author homepage: blog.ircmaxell.com
*
* Document: http://php.net/manual/zh/book.password.php
*/

/**
* generate
*/
$mypass = password_hash('mypassword', PASSWORD_DEFAULT, ['cost' => 12]);

/**
* validate.
*/
var_dump(password_verify('mypassword', $mypass));

Posted in PHP | Leave a comment

HTML 安全过滤

  1. $html = '<script type="text/javascript">alert("test")</script>';
  2. print htmlentities($html, ENT_QUOTES, 'UTF-8');
Posted in PHP | Leave a comment