PHP Version >= 5.0.0 Nesting Limit of 20. PHP Version >= 5.2.3 Nesting Limit of 128. PHP Version >= 5.3.0 Nesting Limit of 512. Small footprint vs PHP’s serialize’d string. serialize() & unserialize()
serialize
PHP Version >= 4.0.0 You’re storing objects that need to be unserialized as the correct class(反序列化的对象依然可以被正常调用)
Serialization of ‘Closure’ is not allowed
Apparently anonymous functions cannot be serialized.(匿名函数不能被序列化)
Example
1 2 3 4
$function = function () { return"ABC"; }; serialize($function); // would throw error
</body> <script> var worker = new Worker("task.js"); worker.postMessage( { id:1, msg:'Hello World' } ); worker.onmessage=function(message){ var data = message.data; console.log(JSON.stringify(data)); worker.terminate(); }; worker.onerror=function(error){ console.log(error.filename,error.lineno,error.message); } </script> </html>
task.js
1 2 3 4 5
onmessage= function(message){ var data=message.data; data.msg = 'Hi from task.js'; postMessage(data); }
例子二: 计数功能
index.html
1 2 3 4 5 6 7 8 9 10 11 12 13
<script> var worker = new Worker("task.js"); worker.onmessage=function(message){ var data = message.data; console.log(JSON.stringify(data)); //终止woker //worker.terminate(); }; worker.onerror=function(error){ console.log(error.filename,error.lineno,error.message); } </script>
task.js
1 2 3 4 5 6 7 8
var i=0; functiontimedCount() { i=i+1; postMessage(i); setTimeout("timedCount()",500); } timedCount();
//Get current page form url e.g. &page=6 $currentPage = LengthAwarePaginator::resolveCurrentPage();
//Create a new Laravel collection from the array data $collection = new Collection($searchResults);
//Define how many items we want to be visible in each page $perPage = 5;
//Slice the collection to get the items to display in current page $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();
//Create our paginator and pass it to the view $paginatedSearchResults= new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);