修改php-beast扩展

vim beast.c

124 line:

zend_module_entry beast_module_entry = {
  2 #if ZEND_MODULE_API_NO >= 20010901
  1     STANDARD_MODULE_HEADER,
  0 #endif                                                                                                                                                                              
  1     “beast”, //扩展名  在phpinfo中显示的扩展名 可随意修改,迷惑作用
  2     beast_functions,
  3     PHP_MINIT(beast),
  4     PHP_MSHUTDOWN(beast),
  5     PHP_RINIT(beast),
  6     PHP_RSHUTDOWN(beast),
  7     PHP_MINFO(beast),

zend_module_entry beast_module_entry = {
  2 #if ZEND_MODULE_API_NO >= 20010901
  1     STANDARD_MODULE_HEADER,
  0 #endif                                                                                                                                                                              
  1     “swoolecompller”,  //扩展名  在phpinfo中显示的扩展名 可随意修改,迷惑作用
  2     beast_functions,
  3     PHP_MINIT(beast),
  4     PHP_MSHUTDOWN(beast),
  5     PHP_RINIT(beast),
  6     PHP_RSHUTDOWN(beast),
  7     PHP_MINFO(beast),

1417 line:

PHP_MINFO_FUNCTION(beast)                                                                                                                                                           
  1 {
  2     php_info_print_table_start();
  3     php_info_print_table_header(2,
  4         “beast V” BEAST_VERSION ” support”, “enabled”);
  5     php_info_print_table_end();
  6 
  7     DISPLAY_INI_ENTRIES();
  8 }

修改为

PHP_MINFO_FUNCTION(beast)                                                                                                                                                           
  1 {
  2     //php_info_print_table_start();
  3     //php_info_print_table_header(2,
  4      //   “beast V111111″ BEAST_VERSION ” support”, “enabled”);
  5     //php_info_print_table_end();
  6 
  7     //DISPLAY_INI_ENTRIES();
  8 }

也可以在 vim php_beast.h  
PHP_MINFO_FUNCTION(beast);  注释掉此行应用。

mysql mark

#update 子查询 limit

update vi_works du,(select voteid from public_vote ORDER by num DESC limit 0,2) b set du.state=2 where du.id=b.voteid and du.state=1;



update vi_works du,(select * from vi_works ORDER by public_vote DESC limit 0,2) b set du.state=2 where du.id=b.id and du.state=1;

javascript 实现递归转非递归 并同步

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="//cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="testapp" ng-controller="testctl">
    <input type="button" ng-click="one()" value="test">
</div>

<script>
    (function () {
        'use strict';
        angular
                .module('testapp', [
                ])
                .controller('testctl',['$scope','$http','$q',function ($scope,$http,$q) {

                    function addTask(fun, delay) {
                        if (typeof fun == 'function') {
                            var argu = Array.prototype.slice.call(arguments, 2);
                            var f = (function () {
                                fun.apply(null, argu);
                            });
                            return window.setTimeout(f, delay);
                        }
                        return window.setTimeout(fun, delay);
                    }

                    $scope.one = function (page) {
                        $scope.deferral_local = $q.defer();
                        page = page || 1;
                        var allpage=10;
                        $q.when($scope.splitfile(page)).then(function () {
                            page=page+1;
                            if(page<=allpage){
                                addTask($scope.one,100,page,"参数2","参数3","参数4");
                            }
                        });
                    };

                    $scope.dosomething = function (currentpage) {
                        /*
                        $http.get("/xxx.php").success(function (response) {
                            $scope.deferral_local.resolve('good');
                        });
                        */
                        $timeout(function () {
                            console.log(currentpage);
                            $scope.deferral_local.resolve('good');
                        },1000);

                        return $scope.deferral_local.promise;
                    };

                }]);
    }());

</script>


<script>

    /*
    for(var page=1;page<=10;page++){
        dosomething(page);
    }
    */

    /*
    function one(page) {
        page = page ||1;
        dosomething(page);
        page=page+1;
        if(page>10){
            return ;
        }else{
            one(page);
        }
    }
    */

</script>

</body>
</html>

upstream timed out (110: Connection timed out) while reading response header from upstream 故障

Blog的phpmyadmin登陆上去操作, 结果一直504,    查看日志显示

upstream timed out (110: Connection timed out) while reading response header from upstream  错误。

一直认为是php-fpm的总是,结果查找了一下, 原来是iptables的lo没有添加放行(以前mysql的3306端口禁止对外连接)

-A INPUT -i lo -j ACCEPT                                                                                                                                                                                    
-A OUTPUT -o lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j DROP

javascript 计算文件md5

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://newpass.com/static/vendor/angular/angular.min.js"></script>
    <script src="//cdn.bootcss.com/jquery/3.1.1/jquery.js"></script>
    <script src="//cdn.rawgit.com/satazor/SparkMD5/master/spark-md5.min.js"></script>

</head>
<body>


<div ng-app="testapp" ng-controller="testctl">
    <input type="button" ng-click="two()" value="two">

<input id="file" type="file">
</div>

<script>
    (function () {
        'use strict';
        window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
        angular
                .module('testapp', [
                ])
                .controller('testctl',['$scope','$timeout','$http','$q',function ($scope,$timeout,$http,$q) {

                    $scope.two = function () {
                        var xx=$('#file').get(0).files[0];
                        $q.when($scope.md5(xx)).then(function (e) {
                            console.log(e);
                        });
                    };

                    $scope.md5 = function (file) {
                        var deferral_local = $q.defer();

                        var defer = $q.defer();
                        var promise = defer.promise;

                        var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
                                chunkSize = 2097152, // read in chunks of 2MB
                                chunks = Math.ceil(file.size / chunkSize),
                                currentChunk = 0,
                                spark = new SparkMD5.ArrayBuffer();

                        function loadNext() {
                            var fileReader = new FileReader();
                            fileReader.onload = function (e) {
                                spark.append(e.target.result); // append array buffer
                                currentChunk++;
                                if (currentChunk < chunks)
                                    loadNext();
                                else
                                    defer.resolve(spark.end());
                            };
                            var start = currentChunk * chunkSize,
                                    end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
                            fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
                        }

                        promise.then(loadNext())
                                .then(function (md5) {
                                    deferral_local.resolve( { status: md5 } );
                                });

                        return deferral_local.promise;
                    }
                }]);

    }());
</script>

</body>
</html>

javascript 分片下载

#html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://newpass.com/static/vendor/angular/angular.min.js"></script>
    <script src="http://newpass.com/test/md51/md5.js"></script>
    <script src="//cdn.rawgit.com/satazor/SparkMD5/master/spark-md5.min.js"></script>

</head>
<body>
<div ng-app="testapp" ng-controller="testctl">
    <input type="button" ng-click="one()" value="one">
</div>

<script>
    (function () {
        'use strict';
        window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
        angular
                .module('testapp', [
                ])
                .controller('testctl',['$scope','$timeout','$http','$q',function ($scope,$timeout,$http,$q) {
                    $scope.isdel=false;

                    $scope.md5 = function (file) {
                        var deferral_local = $q.defer();
                        var defer = $q.defer();
                        var promise = defer.promise;

                        var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
                        var persize = 2097152; // read in chunks of 2MB
                        var allpage = Math.ceil(file.size / persize);
                        var page = 0;
                        var spark = new SparkMD5.ArrayBuffer();

                        function loadNext() {
                            var fileReader = new FileReader();
                            fileReader.onload = function (e) {
                                spark.append(e.target.result); // append array buffer
                                page = page+1;
                                if (page < allpage)
                                    loadNext();
                                else
                                    defer.resolve(spark.end());
                            };
                            var start = page * persize;
                            var end = ((start + persize) >= file.size) ? file.size : start + persize;
                            fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
                        }

                        promise.then(loadNext())
                                .then(function (md5) {
                                    deferral_local.resolve( { status: md5 } );
                                });

                        return deferral_local.promise;
                    };


                    $scope.listfile = function () {
                        window.requestFileSystem(window.TEMPORARY, 5*1024*1024*1024, function(fs) {
                            fs.root.getFile('aw.txt', {create: false}, function (fileEntry) {
                                fileEntry.file(function (file) {
                                    $q.when($scope.md5(file)).then(function (md5) {
                                        console.log(md5);
                                        var link = document.createElement("a");
                                        link.setAttribute("href", fileEntry.toURL());
                                        link.setAttribute("download", "xxx.txt");
                                        link.style.visibility = 'hidden';
                                        document.body.appendChild(link);
                                        link.click();
                                        document.body.removeChild(link);
                                    });
                                });
                            });
                            });
                    };

                    $scope.one = function () {
                        $scope.defer = $q.defer();
                        $scope.promise = $scope.defer.promise;
                        $scope.promise.then($scope.three()).then(function () {
                            $scope.listfile();
                        });

                    };


                    $scope.downloadfile = function (page){
                        page = page || 1;

                        if(page === 1 && !$scope.isdel){
                            window.requestFileSystem(window.TEMPORARY, 5*1024*1024*1024, function(fs) {
                                fs.root.getFile('aw.txt', {create: false}, function (fileEntry) {
                                    if (fileEntry.isFile && !$scope.isdel) {
                                        fileEntry.remove(function () {
                                            console.log('File successufully removed.');
                                            $scope.isdel=true;
                                            $scope.three();
                                        }, function(){
                                            console.log(1111);
                                        });
                                    }else{
                                        $scope.isdel=true;
                                        $scope.three();
                                    }
                                },function(e){
                                    $scope.isdel=true;
                                    $scope.three();
                                    console.log(2222);
                                    console.log(e);
                                });
                            },function(){
                                console.log(3333);
                            });
                        }else{
                            $http.get("/test/down1/5.php?page="+page).success(function (response){
                                page = page+1;
                                window.requestFileSystem(window.TEMPORARY, 5*1024*1024*1024, function(fs){
                                    fs.root.getFile('aw.txt', {create: true}, function(fileEntry) {
                                        fileEntry.createWriter(function(fileWriter) {
                                            window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder;
                                            fileWriter.seek(fileWriter.length);

                                            $scope.byteCharacters = atob(response.content);
                                            $scope.bytesLength = $scope.byteCharacters.length;
                                            $scope.bytes = new Array($scope.bytesLength);
                                            for(var i=0; i<$scope.bytesLength;i++){
                                                $scope.bytes[i] = $scope.byteCharacters[i].charCodeAt(0);
                                            }
                                            var content_tmp=new Uint8Array($scope.bytes);

                                            var blob = new Blob([content_tmp]);
                                            fileWriter.write(blob);
                                            console.log("gggggg");
                                            fileWriter.onwriteend = function (e) {
                                                if(page>response.allpage){
                                                    $scope.isdel=false;
                                                    $scope.defer.resolve(fileEntry);
                                                }else{
                                                    $scope.downloadfile(page);
                                                }
                                            }
                                        }, function(e){
                                            console.log(44444);
                                            console.log(e);
                                        });
                                    }, function(){
                                        console.log(555555);
                                    });
                                }, function(){
                                    console.log(66666);
                                });
                            });

                        }
                    };

                }]);

    }());

</script>

</body>
</html>

#php

$page=isset($_GET['page'])?$_GET['page']:1;
$perpage=30;
$filename="t.txt";
$size=filesize($filename);
$file = fopen($filename,"r");
$allpage = ceil($size/$perpage);
$start = ($page-1)*$perpage;
fseek($file,$start,SEEK_SET);
$content = fread($file,$perpage);

$result['allpage']=$allpage;
$result['page']=$page;
$result['content']=$content;

echo json_encode($result);

base64 to blob

function base64toBlob(base64Data, contentType) {
    contentType = contentType || '';
    var sliceSize = 1024;
    var byteCharacters = atob(base64Data);
    var bytesLength = byteCharacters.length;
    var slicesCount = Math.ceil(bytesLength / sliceSize);
    var byteArrays = new Array(slicesCount);

    for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
        var begin = sliceIndex * sliceSize;
        var end = Math.min(begin + sliceSize, bytesLength);

        var bytes = new Array(end - begin);
        for (var offset = begin, i = 0 ; offset < end; ++i, ++offset) {
            bytes[i] = byteCharacters[offset].charCodeAt(0);
        }
        byteArrays[sliceIndex] = new Uint8Array(bytes);
    }
    return new Blob(byteArrays, { type: contentType });
}

ajax jquery angular 上传文件与分隔上传

简单总结下

#ajax上传文件

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("POST", "2.php", false);
    var formData = new FormData();
    var f = button.form;
    var file = f['file']['files'][0];
    formData.append('abc', data, "xxx.txt");
    xmlhttp.send(formData);
   
        $.ajax({
            url:"2.php",
            type:'POST',
            data:formData,
            processData: false,
            contentType: false,
            success:function(result){
        }});

#服务端很简单:

$tmp_name = $_FILES["abc"]["tmp_name"];
$target = "end.txt";
if(is_file($target)){
    $target_old = $target;
    $target="tmp.txt";
}
move_uploaded_file($tmp_name, $target);

#html:

<form method="POST" name="form1" action="2.php" enctype="multipart/form-data">
    <input id='file' type='file' name='file' onchange="" />
    <input id='button' name='submit' type='button' value="上传" onclick="chunk_upload(this)"/>
</form>

#angular

                            $http({
                                method: 'POST',
                                url: '2.php',
                                headers: {
                                    'Content-Type': undefined
                                },
                                data: {
                                    email: 'aaaa@aaa.com',
                                    token: 'bbbbasdfasdfasdf',
                                    abc: $scope.filesplitdata
                                },
                                transformRequest: function (data, headersGetter) {
                                    var formData = new FormData();
                                    angular.forEach(data, function (value, key) {
                                        formData.append(key, value);
                                    });

                                    var headers = headersGetter();
                                    delete headers['Content-Type'];

                                    return formData;
                                }
                            }).success(function (data) {
                                //alert(data);
                            }).error(function (data, status) {
                            });

#接下来是分片上传

#ajax分片上传
var fileSplitSize = 1024 * 1024;     //1024 = 1kb   1024*1024 =1Mb
var start = 0, end = 0;
var i = 0;
// 文件段上传
function chunk_upload(button) {
    var xmlhttp = new XMLHttpRequest();
    var formData = new FormData();
    xmlhttp.open("POST", "2.php", false);
    var f = button.form;
    var file = f['file']['files'][0];
    var size = file.size;
    end = start + fileSplitSize;
    if (end > size) {
        i = -1;
        end = size;
    } else {
        i += 1;
        end = end;
    }  //按大小切割文件段
    var data = file.slice(start, end);
    var r = new FileReader();
    r.readAsBinaryString(data);

    $(r).load(function (e) {
        var bolb = e.target.result;
        //var check = CryptoJS.MD5(bolb).toString();
        formData.append('abc', data, "xxx.txt");
        xmlhttp.send(formData);
       
        if (xmlhttp.status == 200) {
            if (end == size) {
                var backtext = xmlhttp.responseText;
                alert(backtext);
            } else {
                //alert("上传完成第" + i + "段");
                start = end;
                chunk_upload(button);
            }
        } else {
            alert("上传错误");
            //chunk_upload(button);
        }

    });
}
#jquery 分片上传
var fileSplitSize = 1024 * 1024 *10 ;
var start = 0, end = 0;
var i = 0;
// 文件段上传
function chunk_upload(button) {
    var formData = new FormData();
    var f = button.form;
    var file = f['file']['files'][0];
    var size = file.size;
    end = start + fileSplitSize;
    if (end > size) {
        i = -1;
        end = size;
    } else {
        i += 1;
        end = end;
    }  //按大小切割文件段
    var data = file.slice(start, end);
    var r = new FileReader();
    r.readAsBinaryString(data);

    $(r).load(function (e) {
        var bolb = e.target.result;
        //var check = CryptoJS.MD5(bolb).toString(); 
        formData.append('abc', data, "xxx.txt");

        $.ajax({
            url:"2.php",
            type:'POST',
            data:formData,
            processData: false,
            contentType: false,
            success:function(result){
                if (end == size) {
                    alert('good');
                } else {
                    //alert("上传完成第" + i + "段");
                    start = end;
                    chunk_upload(button);
                }
        }});

    });
}

#angularjs分片上传

    (function () {
        'use strict';

        angular
                .module('test', [
                ])
                .directive('file', function () {
                    return {
                        scope: {
                            file: '='
                        },
                        link: function (scope, el, attrs) {
                            el.bind('change', function (event) {
                                var file = event.target.files[0];
                                scope.file = file ? file : undefined;
                                scope.$apply();
                            });
                        }
                    };
                })
                .controller('testctl',['$scope','$http',function ($scope,$http) {
                    $scope.uptest = function (currentpage) {
                        var persize=1024;
                        var allpage = Math.ceil($scope.file.size/persize);
                        if(typeof currentpage === "undefined"){
                            currentpage=1;
                        }
                        var start = (currentpage-1)*persize;
                        var end = start+persize;
                        if(currentpage===allpage){
                            end=$scope.file.size;
                        }
                        $scope.filesplitdata = $scope.file.slice(start, end);

                        currentpage=currentpage+1;
                        $http({
                            method: 'POST',
                            url: '2.php',
                            headers: {
                                'Content-Type': undefined
                            },
                            data: {
                                email: 'aaaa@aaa.com',
                                token: 'bbbbasdfasdfasdf',
                                abc: $scope.filesplitdata
                            },
                            transformRequest: function (data, headersGetter) {
                                var formData = new FormData();
                                angular.forEach(data, function (value, key) {
                                    formData.append(key, value);
                                });

                                var headers = headersGetter();
                                delete headers['Content-Type'];

                                return formData;
                            }
                        }).success(function (data) {
                            if(currentpage>allpage){
                                alert("gooood");
                            }else{
                                $scope.uptest(currentpage);
                            }
                            //alert(data);
                        }).error(function (data, status) {
                        });
                        
                    };
                }]);
    }());

#angularjs对应html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="//cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
    <script src="crypto-js.js"></script>
    <script src="xxx.js"></script>
</head>
<body>
<div ng-app="test" ng-controller="testctl">
    <input type="file" file="file" required />

    <input type="button" ng-click="uptest(1)">

</div>


</body>
</html>