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’]]);…

PHP implements grabbing Google IP and automatically modifying the hosts file, _PHP tutorial

PHP implements grabbing Google IP and automatically modifying the hosts file, Out of boredom, I actually found a PHP version to grab the google hosts file. I tried it and it still works. I pinged the IP and the delay was not very high. When I opened the web page and tested it, it was also very fast. Everyone is interested. If so, you can try it. Automatically updates the hosts file without overwriting existing records. It is convenient to use and does not require copying -> opening the hosts file -> pasting every time. php file: <?php /** * No need to go through Google on the wall * @author Enjoy yourself and enjoy yourself * Date: 2015/2/6 * Time: 11:42 */ define(‘START_TAG’,’#google-hosts-2015′); define(‘END_TAG’,’#google-hosts-2015-end’); if(!empty($argv[1])){ $params = array(); parse_str($argv[1], $params); if(isset($params[‘url’])){ define(‘GOOGLE_HOST_URL’, $params[‘url’]); } if(isset($params[‘del’])){ define(‘DELETE_GOOGLE_HOST’,true); } } defined(‘GOOGLE_HOST_URL’) || define(‘GOOGLE_HOST_URL’, ‘http://www.360kb.com/kb/2_150.html’); if(PHP_OS == ‘WINNT’){ define(‘HOSTS_FILE_PATH’, ‘C:WindowsSystem32driversetchosts’); }else if(in_array(PHP_OS, array(‘Linux’,’Darwin’,’FreeBSD’,’OpenBSD’,’WIN32′,’Windows’,’Unix’))){ define(‘HOSTS_FILE_PATH’, ‘/etc/hosts’); }else{ die(‘Unsupported system!’.PHP_EOL); } if(!is_writable(HOSTS_FILE_PATH)){ die(‘Without permission, please use the root user to perform!’.PHP_EOL); } $hosts = file_get_contents(HOSTS_FILE_PATH); $startPos = strpos($hosts, START_TAG); if(!defined(‘DELETE_GOOGLE_HOST’)){ $gs = get_google_hosts(); echo GOOGLE_HOST_URL.PHP_EOL; echo $gs.PHP_EOL; }else{ $gs = ”; echo ‘reset hosts’.PHP_EOL; } if($startPos){ $_tmp = substr($hosts, $startPos, strpos($hosts, END_TAG) – $startPos…

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, _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, _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 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…

PHP runs under iis in fastCGI mode. File system permission problems encountered and solutions, _PHP tutorial

PHP runs under iis in fastCGI mode. File system permission problems encountered and solutions, _PHP tutorial

php runs under iis in fastCGI mode, and encountered file system permission problems and solutions. Today I am going to run a php demo under IIS. The website is in IIS The configuration below is like this: The application pool is .net framework 2.0 in integrated mode (2.0 or 4.0 does not matter, because PHP runs in fastCGI mode), and the application pool identifier is configured as IIS built-in NETWORKSERVICE, the authentication method used is Anonymous Authentication. When I opened the local website and accessed the php page, a 500 error occurred. Okay, it’s a permissions issue. The simplest solution is to set the permissions of C:\Users\Administrator\PhpstormProjects\phpDemo to Everyone, and allow full control: Revisited the php page and succeeded: The above method is simple enough, but it is also too unsafe. It is usually no problem to set up a local demo to do this, but when it is actually online, it will cause problems sooner or later. So reset it and give the read-only permissions in the directory to the NETWRORKSERVICE account and try again However, the problem is still not solved. When accessing, a 401 error occurs The error message includes the display that the logged-in user is…

File system permission issues and solutions when php is run in fastCGI mode, _PHP tutorial

File system permission issues and solutions when php is run in fastCGI mode, _PHP tutorial

File system permission problems and solutions when php is run in fastCGI mode, Today I am going to run a php demo under IIS. The configuration of the website under IIS is as follows : The application pool is .net framework 2.0 in integrated mode (2.0 or 4.0 does not matter, because PHP runs in fastCGI mode), the application pool identity is configured as IIS built-in NETWORKSERVICE, and the authentication method used is anonymous identity verify. When I opened the local website and accessed the php page, a 500 error occurred. Okay, it’s a permissions issue. The simplest solution is to set the permissions of C:\Users\Administrator\PhpstormProjects\phpDemo to Everyone, and allow full control: Revisited the php page and succeeded: The above method is simple enough, but it is also too unsafe. It is usually no problem to set up a local demo to do this, but when it is actually online, it will cause problems sooner or later. So reset it and give the read-only permissions in the directory to the NETWRORKSERVICE account and try again However, the problem is still not solved. When accessing, a 401 error occurs The error message includes the display that the logged-in user is anonymous.…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索