Category: Php / Pear / Mysql / Node.js

在PHP中使用memcached提高动态网站性能, memcached, memcache, memcached数据库缓存类

  确认是否已经安装memcached:Verify Installation php -m | grep memcached   视频:   memcached 函数 看官网:http://php.net/manual/zh/book.memcached.php Memcached — Memcached类 Memcached::add — 向一个新的key下面增加一个元素 Memcached::addByKey — 在指定服务器上的一个新的key下增加一个元素 Memcached::addServer — 向服务器池中增加一个服务器 Memcached::addServers — 向服务器池中增加多台服务… Read More

jQuery: 选择器包含特殊字符,选择器包含括号,jQuery selector for inputs with square brackets in the name attribute

  看以下代码,一目了然: Per the jQuery documentation, try this: $('input[inputName\\[\\]=someValue]') [EDIT] However, I’m not sure that’s the right syntax for your selector. You probably want: $('input[name="inputName"][value="someValue"]')   本文:jQuery: 选择器包含特殊字符,选择器包含括号,jQuery selector for inputs with square bracket… Read More

MySQL:mysql索引优化, mysql全文检索, mysql 不等于 优化, 全值匹配, 最佳左前缀法则

  Explain优化查询检测 所谓索引就是为特定的mysql字段进行一些特定的算法排序,比如二叉树的算法和哈希算法,哈希算法是通过建立特征值,然后根据特征值来快速查找,而用的最多,并且是mysql默认的就是二叉树算法 BTREE,通过BTREE算法建立索引的字段,比如扫描20行就能得到未使用BTREE前扫描了2^20行的结果,具体的实现方式后续本博客会出一个算法专题里面会有具体的分析讨论; EXPLAIN可以帮助开发人员分析SQL问题,explain显示了mysql如何使用索引来处理select语句以及连接表,可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上… Read More

解决Mysql错误:Too many connections的方法, mysql_connect(): Too many connections

  通过sql语句参看你的最大连接数: SHOW VARIABLES LIKE "max_connections"   修复的方法,以下任选其一:  为了防止DDoS攻击,添加一个不修改任何配置,只是在代码中添加一个 sleep(1);  通过sql语句增加链接数: SET GLOBAL max_connections = 1024; 或者通过修改 my.cnf (/etc/my.cnf 或者你自定义的~/.my.cnf)配置文件,在 [mysqld] 下面添加一行 max_connections=1024; 非使用mysqld脚本自动启动的用户。 修改$MYSQL_HOME/bin/mysqld_safe文件 例… Read More

mongodb 联表查询方法, PHP操作远程mongodb数据库

  本篇是 PHP操作远程mongodb数据库, MongoDB PHP Library, php connects with remote MongoDB 的延伸:   这里只对同库联表查询做介绍,跨库联表查询可能在之后也会介绍(因为公司架构变动,之后可能会联表查询) 我用到的联表查询有两种,一种是mongoose的populate,一种是$lookup populate populate是使用外键关联子表 例如现在有一张订单表结构(动态外键): var orderSchema = new mongoose.Schema({ uid: { type: String, required: true }, // 用户id amount… Read More

安装不同版本的PHP, 更换PHP默认版本, PHP多版本安装, How to Install Different PHP (5.6, 7.0 and 7.1) Versions in Ubuntu

  PHP(PHP的递归缩写:Hypertext Preprocessor)是一种开源的,流行的通用脚本语言,广泛使用并且最适合开发网站和基于Web的应用程序。它是一种可以嵌入HTML的服务器端脚本语言。 目前,有三种受支持版本的PHP,即PHP 5.6,7.0和7.1。含义PHP 5.3,5.4和5.5都达到了生命的尽头; 安全更新不再支持它们。 在本文中,我们将解释如何使用OndřejSurýPPA在Ubuntu及其衍生产品中安装所有受支持的PHP版本,以及Apache和Nginx Web服务器的大多数请求的PHP扩展。我们还将解释如何设置要在Ubuntu系统上使用的PHP的默认版本。 请注意… Read More

PHP: 控制循环执行次数, do…while与while , goto 跳转位置, if not repeat running

do-while (PHP 4, PHP 5, PHP 7) do-while 循环和 while 循环非常相似,区别在于表达式的值是在每次循环结束时检查而不是开始时。和一般的 while 循环主要的区别是 do-while的循环语句保证会执行一次(表达式的真值在每次循环结束后检查),然而在一般的 while 循环中就不一定了(表达式真值在循环开始时检查,如果一开始就为 FALSE 则整个循环立即终止)。 do-while 循环只有一种语法: <?php $i = 0; do { echo $i; } while ($i > 0); ?> 以上循环将正好运行一次,因为经过第一次循环后,当检查表达式的真值时,其值为 FAL… Read More

报错:CodeIgniter Disallowed Key Characters, disallowed key characters

改用一下的正则表达式 !preg_match("/^[a-z0-9\x{4e00}-\x{9fa5}\:\;\.\,\?\!\@\#\$%\^\*\"\~\'+=\\\ &_\/\.\[\]-\}\{]+$/iu", $str) 修改 Input.php 或者创建自己的 MY_Input.php , 如下: <?php class MY_Input extends CI_Input { /** * Clean Keys * * This is a helper function. To prevent malicious users * from trying to exploit keys we make sure that keys are

MySQL: 永远不要在MySQL中使用“utf8”, MySQL中的utf8mb4和utf8

  最近我遇到了一个 bug,我试着通过 Rails 在以“utf8”编码的 MariaDB 中保存一个 UTF-8 字符串,然后出现了一个离奇的错误: Incorrect string value: ‘\xF0\x9F\x98\x83 <…’ for column ‘summary’ at row 1 我用的是 UTF-8 编码的客户端,服务器也是 UTF-8 编码的,数据库也是,就连要保存的这个字符串“ <…”也是合法的 UTF-8。 问题的症结在于,MySQL 的“utf8”实际上不是真正的 UTF-8。 “utf8”只支持每个字符最多三个字节,而真正的 UTF-8 是每个字符最多四个字节。 MySQL 一直没有修复这个 bug,他们… Read More

PHP: 模拟 POST 提交表单, Sending POST data without form, send a POST request with PHP

  方法有很多种,比如用 AJAX: $.post('/foo.php', { key1: 'value1', key2: 'value2' }, function(result) { alert('successfully posted key1=value1&key2=value2 to foo.php'); }); 又比如用CURL: function httpPost($url, $data) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_qu… Read More

手动升级phpMyAdmin, How to Manually Upgrade phpMyAdmin

  首先要去下载最新版本: phpMyAdmin download page 1. Backup phpMyAdmin 备份当前phpmyadmin # 备份 sudo mv /usr/share/phpmyadmin/ /usr/share/phpmyadmin.bak # 创建新的文件夹 sudo mkdir /usr/share/phpmyadmin/ # 进入这个文件夹 cd /usr/share/phpmyadmin/   2. Download and Extract phpMyAdmin 下载并解压 下载需要的版本: phpMyAdmin download page # 我们用4.8.3版本测试 sudo wget https://… Read More

PHP操作远程mongodb数据库, MongoDB PHP Library, php connects with remote MongoDB

MongoDB PHP Library 项目地址:https://github.com/mongodb/mongo-php-library 官网手册:https://docs.mongodb.com/php-library/master/tutorial/crud/ php driver for mongodb : 安装mongodb的php驱动:Ubuntu: 安装MongoDB, Install MongoDB With Apache2, PHP 7.2 Support On Ubuntu 16.04 / 17.10 / 18.04 官网可视化工具:https://www.mongodb.com/download-center?initi… Read More

PHP Google APIs: 获取gmail邮件, php搜索gmail邮件, php gmail api, Gmail to RSS Feed, PHP Google APIs Client Library

用到的工具: Google APIs Client Library for PHP FeedWriter PHP 快速入门 google apis:Google Developers   用法:gmail2rss.php <?php require 'vendor/autoload.php'; // composer 安装项目后,引入 autoload.php define('APPLICATION_NAME', 'Gmail To RSS'); define('CREDENTIALS_PATH', '~/.credentials/gmail-to-rss.json'); define('CLIENT_SECRET_PATH', 'c… Read More