How to use prerender on your website?

https://prerender.io/documentation

It’s a simple way to test prerender, maybe you need change some code in your project.

1. Singup a account at https://prerender.io
2. Setup a prerendertest directory,like below:
/prerendertest/data.php
/prerendertest/index.html

/prerendertest/data.php

    {
    "records":[
    {"Name":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"},
    {"Name":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"},
    {"Name":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"},
    {"Name":"Around the Horn","City":"London","Country":"UK"},
    {"Name":"B's Beverages","City":"London","Country":"UK"},
    {"Name":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"},
    {"Name":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"},
    {"Name":"Blondel père et fils","City":"Strasbourg","Country":"France"},
    {"Name":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"},
    {"Name":"Bon app'","City":"Marseille","Country":"France"},
    {"Name":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"},
    {"Name":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"},
    {"Name":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"},
    {"Name":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"},
    {"Name":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"}
    ]
    }

/prerendertest/index.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="fragment" content="!">
    <script src="https://cdn.bootcss.com/angular.js/1.6.3/angular.min.js"></script>
    </head>
    <body>
 
    <div ng-app="myApp" ng-controller="customersCtrl">
 
    <table>
      <tr ng-repeat="x in names">
        <td>{{ x.Name }}</td>
        <td>{{ x.Country }}</td>
      </tr>
    </table>
 
    </div>
 
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("/prerendertest/data.php")
        .then(function (result) {
            $scope.names = result.data.records;
        });
    });
    </script>
 
    </body>
    </html>

3. Config your nginx
Reference here https://gist.github.com/thoop/8165802

4. Visit http://xxx.com/prerendertest/index.html?_escaped_fragment_=, then view source of the html

MYSQL order by rand() optimize

http://www.jcodecraeer.com/a/chengxusheji/java/2017/0109/6960.html

No more “order by rand()” in code.

#0.0012s
SELECT * FROM `content` 
WHERE id >= (SELECT FLOOR(RAND() * (SELECT MAX(id) FROM `content`)))  
ORDER BY id ASC LIMIT 10;
 
#0.2s
SELECT * FROM `content`
ORDER BY RAND() LIMIT 10;

SWOT个人分析

S 擅长写一些服务端,应用层的代码。
W 不擅长学习新的代码语言,不擅长写客户端等。眼光不够长远,格局不够开阔。对用户的喜好不敏感,不擅长捕获。

O 通过和老板合作,团队成员合作完成一个产品的制作。通过和别人合作运营产品,提供技术支持。
T 局限于自己的小思维,不和人沟通,不结交认识心得朋友

php>=5.5版本,使用PHP CURL POST文件上传

参考:http://blog.csdn.net/ljfrocky/article/details/46009251

php55CurlPost.php

<?php
 
define('FORM_BOUNDARY', uniqid('----WebKitFormBoundary'));
define('FORM_HYPHENS', '--');
define('FORM_EOL', "\r\n");
define('FORM_IMG_FIELD_NAME', 'img[]');
 
/*
 * 要POST的文本数据和本地图片
 */
$text_data = [
    'username' => 'Tom',
    'password' => '123456',
];
$img_data = [
    '111.jpg' => '/Applications/XAMPP/xamppfiles/htdocs/indomeme.yyy/111.jpg',
    '222.jpg' => '/Applications/XAMPP/xamppfiles/htdocs/indomeme.yyy/222.jpg',
];
 
$url = 'http://indomeme.yyy/php55Upload.php'; // 服务器URL,根据实际情况进行修改
$req_headers = [
    'Content-Type: multipart/form-data; boundary=' . FORM_BOUNDARY,
];
$post_data = '';
 
array_walk($text_data, 'text_form_data_splice');
array_walk($img_data, 'image_form_data_splice');
if (!empty($post_data)) {
    $post_data .= FORM_HYPHENS . FORM_BOUNDARY . FORM_HYPHENS;
}
 
$result = curl_post($url, $req_headers, $post_data);
 
var_dump($result);
 
/**
 * 拼接文本类型的表单项
 * @param string $value 表单项的域值
 * @param string $key 表单项的域名
 */
function text_form_data_splice($value, $key) {
    global $post_data;
    $post_data .= FORM_HYPHENS . FORM_BOUNDARY . FORM_EOL
               . "Content-Disposition: form-data; name=\"$key\""
               . FORM_EOL . FORM_EOL
               . $value . FORM_EOL;
}
 
/**
 * 拼接上传图片类型的表单项
 * @param string $value 图片在本地的路径
 * @param string $key 图片名称
 */
function image_form_data_splice($value, $key) {
    global $post_data;
 
    $image_type = exif_imagetype($value);
    if ($image_type === false) {
        return;
    }
    $mime_type = image_type_to_mime_type($image_type);
    $post_data .= FORM_HYPHENS . FORM_BOUNDARY . FORM_EOL
               . "Content-Disposition: form-data; name=\"" . FORM_IMG_FIELD_NAME
               . "\"; filename=\"$key\"" . FORM_EOL
               . "Content-Type: $mime_type" . FORM_EOL . FORM_EOL
               . file_get_contents($value) . FORM_EOL;
}
 
function curl_post($url, array $header, $data) {
    $options = [
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER => false,
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => $header,
        CURLOPT_POSTFIELDS => $data,
    ];
 
    $ch = curl_init();
    curl_setopt_array($ch, $options);
    $resp = curl_exec($ch);
    if (curl_errno($ch)) {
        $ret = [
            'code' => -1,
            'resp' => curl_error($ch),
        ];
    } else {
        $ret = [
            'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE),
            'resp' => $resp,
        ];
    }
    curl_close($ch);
 
    return $ret;
}

php55Upload.php

<?php
var_dump($_FILES);
var_dump($_POST);

php图片质量压缩imagecopyresampled

http://www.jb51.net/article/57580.htm

//用于对图片进行缩放
function thumb($filename,$newFilename,$quality=90,$width='',$height=''){
    //获取原图像$filename的宽度$width_orig和高度$height_orig
    list($width_orig,$height_orig) = getimagesize($filename);
 
    if($width=='' && $height==''){
      $width = $width_orig;
      $height = $height_orig;
    }else{
      //根据参数$width和$height值,换算出等比例缩放的高度和宽度
      if ($width && ($width_orig<$height_orig)){
          $width = ($height/$height_orig)*$width_orig;
      }else{
          $height = ($width / $width_orig)*$height_orig;
      }
    }
 
    //将原图缩放到这个新创建的图片资源中
    $image_p = imagecreatetruecolor($width, $height);
    //获取原图的图像资源
    $image = imagecreatefromjpeg($filename);
 
    //使用imagecopyresampled()函数进行缩放设置
    imagecopyresampled($image_p,$image,0,0,0,0,$width,$height,$width_orig,$height_orig);
 
    //将缩放后的图片$image_p保存,100(质量最佳,文件最大)
    imagejpeg($image_p,$newFilename,$quality);
 
    imagedestroy($image_p);
    imagedestroy($image);
}
thumb("1.jpg",'./Runtime/2.jpg');