使用ssh远程登录服务器的时候,要进行后台任务操作(比如采集),可以用命令nohup php-cgi来运行php,这样就可以关掉ssh客户端后还会在服务器上运行,运行的输出结果记录在用户目录下的nohup.out文件。
{$smarty}保留变量不需要从PHP脚本中分配,是可以在模板中直接访问的数组类型变量,通常被用于访问一些特殊的模板变量。例如,直接在模板中访问页面请求变量、获取访问模板时的时间邮戳、直接访问PHP中的常量、从配置文件中读取变量等。该保留变量中的部分访问介绍如下。
1.在模板中访问页面请求变量
我们可以在PHP脚本中,通过超级全局数组$_GET、$_POST、$_REQUEST获取在客户端以不同方法提交给服务器的数据,也可以通过$_COOKIE或$_SESSION在多个脚本之间跟踪变量,或是通过$_ENV和$_SERVER获取系统环境变量。如果在模板中需要这些数组,可以调用Smarty对象中的assign()方法分配给模板。但在Smarty模板中,直接就可以通过{$smarty}保留变量访问这些页面请求变量。在模板中使用的示例如下所示: 阅读全文…
一直都是使用DISCUZ的获取客户端IP的函数,但今日发现网站使用CDN加速后,网站统计出了问题,获取到的IP有部分是CDN节点的IP,而程序统计是以唯一IP判断,导致统计到的IP比实际IP少很多。改动获取IP的函数后恢复正常。
原获取IP的方法:
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$onlineip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$onlineip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$onlineip = $_SERVER['REMOTE_ADDR'];
}
preg_match("/[\d\.]{7,15}/", $onlineip, $onlineipmatches);
$onlineip = $onlineipmatches[0] ? $onlineipmatches[0] : 'unknown';
unset($onlineipmatches);
阅读全文…
MySQL创建、删除、重建和查看索引命令、掌握创建索引、删除索引、重建索引和查看索引的命今。
1,创建索引(PRIMARY KEY,INDEX,UNIQUE)
支持创建主键索引,联合索引和普通索引命令
mysql>ALTER TABLE tbl_name ADD INDEX index_name (column list);
mysql>ALTER TABLE tbl_name ADD UNIQUE index_name (column list);
mysql>ALTER TABLE tbl_name ADD PRIMARY KEY index_name (column list);
2,删除索引(PRIMARY KEY,INDEX,UNIQUE)
支持删除主键索引,联合索引和普通索引命令
mysql>ALTER TABLE tbl_name DROP INDEX index_name (column list);
mysql>ALTER TABLE tbl_name DROP UNIQUE index_name (column list);
mysql>ALTER TABLE tbl_name DROP PRIMARY KEY index_name (column list);
阅读全文…
ignore_user_abort,这个函数可以帮助我们实现像linux中的cron一样实现计划任务,用户关掉浏览器后还可以执行。
使用方法:先使用函数set_time_limit(0)设置程序的执行时间为无限制。
例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| <?php
// Ignore user aborts and allow the script
// to run forever
ignore_user_abort(true);
set_time_limit(0);
echo 'Testing connection handling in PHP';
// Run a pointless loop that sometime
// hopefully will make us click away from
// page or click the "Stop" button.
while(1)
{
// Did the connection fail?
if(connection_status() != CONNECTION_NORMAL)
{
break;
}
// Sleep for 10 seconds
sleep(10);
}
// If this is reached, then the 'break'
// was triggered from inside the while loop
// So here we can log, or perform any other tasks
// we need without actually being dependent on the
// browser.
?> |
最近需要整理一个整站的php代码规范视图,前几天发现phpCB整理视图非常好,但有个缺点是不能批量处理,使用过程中发现phpCB是一个CMD程序,马上就想到php的system函数调用cmd,想到就做,下面是phpCB批量转换的php程序:
阅读全文…
用phpCodeBeautifier工具可以帮你格式化代码视图,规范代码缩进习惯,很实用的一个工具。
用法:DOS窗口打开phpCodeBeautifier工具目录,语法格式为:
phpCB.exe [options] [filename]
阅读全文…
有些常用的配置变量写入MYSQL比较麻烦,可以写入一个php配置文件,在需要的地方引入这个配置文件即可。写入方法如下(摘入):
$configfile = @file_get_contents('./config.inc.php');
$configfile = trim($configfile);
$configfile = preg_replace("/[$]dbhost\s*\=\s*[\"'].*?[\"'];/is", "\$dbhost = '$dbhost';", $configfile);
$configfile = preg_replace("/[$]dbuser\s*\=\s*[\"'].*?[\"'];/is", "\$dbuser = '$dbuser';", $configfile);
$configfile = preg_replace("/[$]dbpw\s*\=\s*[\"'].*?[\"'];/is", "\$dbpw = '$dbpw';", $configfile);
$configfile = preg_replace("/[$]dbname\s*\=\s*[\"'].*?[\"'];/is", "\$dbname = '$dbname';", $configfile);
$configfile = preg_replace("/[$]adminemail\s*\=\s*[\"'].*?[\"'];/is", "\$adminemail = '$adminemail';", $configfile);
$configfile = preg_replace("/[$]tablepre\s*\=\s*[\"'].*?[\"'];/is", "\$tablepre = '$tablepre';", $configfile);
$configfile = preg_replace("/[$]cookiepre\s*\=\s*[\"'].*?[\"'];/is", "\$cookiepre = '".random(3)."_';", $configfile);
@file_put_contents('./config.inc.php', $configfile);
最新评论