Detailed explanation of the use of MongodbAPI in PHP7, _PHP tutorial
Detailed explanation of the use of Mongodb API in PHP7, Compile and install PHP7 Compile and install PHP7 Mongdb extension #First install a dependent library yum -y install openldap-develwget https://pecl.php.net/get/mongodb-1.1.1.tgz /home/server/php7/bin/phpize #Compile based on your own Depends on the PHP environment./configure –with-php-cOnfig=/home/server/php7/bin/php-config make && make install#If successful, generate a mongodb.so extension in lib/php/extensions/no- debug-non-zts-20151012/Modify php.ini configuration extension=mongodb.so Note: The previous version used the mongo.so extension and the old php-mongodb api It is no longer supported in PHP7, at least not yet. The latest mongodb that supports PHP7 only supports the new version of API (mongodb > 2.6.X version) after compilation Reference materials GITHUB: https://github.com/mongodb/ Official website: http://www.mongodb.org/ PHP official: https://pecl.php.net/package/mongodb http://pecl.php.net/package/mongo [Abandoned, currently only supports PHP5.9999] API manual: http://docs.php.net/manual/en/set.mongodb.php Mongodb API operations Initialize Mongodb connection $manager = new MongoDB/Driver/Manager(“mongodb://127.0.0.1:27017”); var_dump($manager); object(MongoDB/Driver/Manager)#1 (3) { [“request_id”]=> int(1714636915) [“uri”]=> string(25) “mongodb://localhost:27017” [“cluster”]=> array(13) { [“mode”]=> string(6) “direct” [“state”]=> string(4) “born” [“request_id”]=> int(0) [“sockettimeoutms”]=> int(300000) [“last_reconnect”]=> int(0) [“uri”]=> string(25) “mongodb://localhost:27017” [“requires_auth”]=> int(0) [“nodes”]=> array(…) [“max_bson_size”]=> int(16777216) [“max_msg_size”]=> int(50331648) [“sec_latency_ms”]=> int(15) [“peers”]=> array(0) { } [“replSet”]=> NULL }} CURL operations $bulk = new MongoDB/Driver/BulkWrite([‘ordered’ => true]);$bulk->delete([]); $bulk->insert([‘_id’ => 1]); $bulk->insert([‘_id’ => 2]); $bulk->insert([‘_id’ => 3, ‘hello’ => ‘world’]);$bulk->update([‘_id’ => 3], [‘$set’ => [‘hello’ => ‘earth’]]);…
How to clean up temporary system files in batches (language: C#, C/C++, php, python, java), _PHP tutorial
How to clean up temporary system files in batches (languages: C#, C/C++, php, python, java), The language debate has been around for a long time. Let’s do some IO experiments (traversal Files with more than 9G, deleted in batches), try to use facts to compare who is better and who is worse. Operating system: win7 64-bit, file package size: 9.68G. 1. Language: C# Development environment: vs 2013 Total number of lines of code: 43 lines Time taken: 7 seconds Code: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespaceBatchDelete { class Program { static void Main(string[] args) { //Input directory e:\tmp string path; Console.WriteLine(“Enter the directory to be cleaned:”); path = Console.ReadLine(); // start the timer Console.WriteLine(“Start timing:”+DateTime.Now.ToString(“HH:mm:ss”)); // First traverse the matching search and then loop to delete if (Directory.Exists(path)) { Console.Write(“Deleting”); foreach (string fileName in Directory.GetFileSystemEntries(path)) { if (File.Exists(fileName) && fileName.Contains(“cachegrind.out”)) { File.Delete(fileName); } } Console.WriteLine(“”); } else { Console.WriteLine(“This directory does not exist!”); } // Timer ends Console.WriteLine(“End time:” + DateTime.Now.ToString(“HH:mm:ss”)); Console.ReadKey(); } } } Operation renderings: 2. Language: C/C++ Development environment: vs 2013 Total number of lines of code: 50 lines Time taken: 36 seconds Code: #include #include #include #include #include #include…
Reflection call private method practice (php, java), _PHP tutorial
Practice of reflective calling private methods (php, java), There is a common problem in single testing, the private method in the side class cannot be called directly. During the processing, Xiaoyan changes the method permissions through reflection, conducts a single test, shares it, and directly uploads the code. Simple test class Generate a simple test class with only one private method. The code is as follows: <?php/** * Basic template for Cui Xiaohuan’s single test. * * @author cuihuan * @date 2015/11/12 22:15:31 * @version $Revision:1.0$ **/class MyClass {/** * Private method* * @param $params * @return bool */ private function privateFunc($params){if(!isset($params)){return false;}echo "test success";return $params;}} Unit test code The code is as follows: objMyClass = new MyClass();}/** * Use reflection to unit test the private and protect methods in the class* * @param $strMethodName string: Reflection function name* @return ReflectionMethod obj: callback object*/protected static function getPrivateMethod($strMethodName) {$objReflectClass = new ReflectionClass(self::CLASS_NAME);$method = $objReflectClass->getMethod($strMethodName);$method->setAccessible(true );return $method;}/** * @brief: Test the call of private function*/public function testPrivateFunc(){$testCase = ‘just a test string’;//Reflect this class $testFunc = self::getPrivateMethod( ‘privateFunc’);$res = $testFunc->invokeArgs($this->objMyClass, array($testCase));$this->assertEquals($testCase, $res);$this->expectOutputRegex(‘/success/ i’);//Catch no parameter exception test try { $testFunc->invokeArgs($this->transfer2Pscase, array());} catch (Exception $expected) {$this->assertNotNull($expected);return true ;}$this->fail(self::FAIL);}} Run results cuihuan:test cuixiaohuan$ phpunit…
How to clean up temporary system files in batches (language: C#, C/C++, php, python, java), _PHP tutorial
How to clean up temporary system files in batches (languages: C#, C/C++, php, python, java), The language debate has been around for a long time. Let’s do some IO experiments (traversal Files with more than 9G, deleted in batches), try to use facts to compare who is better and who is worse. Operating system: win7 64-bit, file package size: 9.68G. 1. Language: C# Development environment: vs 2013 Total number of lines of code: 43 lines Time taken: 7 seconds Code: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespaceBatchDelete { class Program { static void Main(string[] args) { //Input directory e:\tmp string path; Console.WriteLine(“Enter the directory to be cleaned:”); path = Console.ReadLine(); // start the timer Console.WriteLine(“Start timing:”+DateTime.Now.ToString(“HH:mm:ss”)); // First traverse the matching search and then loop to delete if (Directory.Exists(path)) { Console.Write(“Deleting”); foreach (string fileName in Directory.GetFileSystemEntries(path)) { if (File.Exists(fileName) && fileName.Contains(“cachegrind.out”)) { File.Delete(fileName); } } Console.WriteLine(“”); } else { Console.WriteLine(“This directory does not exist!”); } // Timer ends Console.WriteLine(“End time:” + DateTime.Now.ToString(“HH:mm:ss”)); Console.ReadKey(); } } } Operation renderings: 2. Language: C/C++ Development environment: vs 2013 Total number of lines of code: 50 lines Time taken: 36 seconds Code: #include #include #include #include #include #include…
PHP+iFrame implements asynchronous file upload without page refresh, _PHP tutorial
PHP+iFrame implements asynchronous file upload without page refresh, The example in this article describes PHP+iFrame’s implementation of asynchronous file upload without page refresh, which is a very practical and common technique. Share it with everyone for your reference. The specific analysis is as follows: Speaking of iframe, fewer and fewer people use it now, and many people believe that it should be replaced by AJAX. This is true, because AJAX is so good. However, there is one situation where I still choose iframe for implementation. This is the asynchronous upload of files that this article is about. If you are interested, you can try it. If you use native AJAX to implement it, it should be much more complicated. First, let’s provide beginners with basic knowledge: 1. The iframe tag usually specifies its name attribute for identification; 2. Determine the submission destination through action (target address) and target (target window, default is _self) in the form; 3. Point the target in the form to the name of the iframe, and the form can be submitted to the hidden frame iframe; 4. The content in the iframe is actually a page, and the parent object in js refers to the parent…
PHP implements image cropping and watermark effect code, _PHP tutorial
PHP implements image cropping and watermark effect code, 3. Image cropping with PHP Before cropping After cropping Effect 4. Add watermark to images with PHP No watermark Add watermark Effect http://www.bkjia.com/PHPjc/887748.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/887748.htmlTechArticlePHP realizes image cropping and adding watermark effect code, 3. PHP crops images p h4 before cropping/h4 img src=”https://www.php1.cn/detail/1.png” style=”border:1px solid red;” /p php header( “content-type”,”te…
PHP implementation of paging: text paging and number paging, _PHP tutorial
PHP implements paging: text paging and number paging, Source: http://www.ido321.com/1086.html Recently, paging is used in projects. The paging function is a frequently used function, so it is encapsulated in the form of a function. //Paging and packaging /** * $pageType paging type 1 is digital paging 2 is text paging * You can pass $pageTotal, $page, $total and other data as parameters, or as global variables in paging (recommended) */ function paging($pageType) { global $pageTotal,$page,$total; if($pageType == 1) { echo ”; echo”; for($i=0; $i <$pageTotal; $i++) { if($page == ($i+1)) { echo ‘.($i+1).'” class=”selected”>’.($i+1). ”; } else { echo ‘.($i+1).'”>’.($i+1).’ ‘; } } echo”; echo”; } else if($pageType == 2) { echo ”; echo ”; echo ”.$page.’/’.$pageTotal.’page | ‘; echo ‘Total’.$total .’ members | ‘; //First page if($page == 1) { echo ‘Home | ‘; echo ‘Previous page | ‘; } else { // $_SERVER[“SCRIPT_NAME”] gets the current script name for easy transplantation //You can also customize constants, the constant values are consistent with the script file name echo ‘.$_SERVER[“SCRIPT_NAME”].'”>Home | ‘; echo ‘.$_SERVER[“SCRIPT_NAME”].’?page=’.($page – 1) .'”>Previous page| ‘; } //Last page if($page == $pageTotal) { echo ‘Next page | ‘; echo ‘Last page | ‘; } else { echo…