1.设置时间脚本执行时间
set_time_limit(0);
2.设置最大执行内存
ini_set('memory_limit','1024M');//设置内存
memory_get_usage();//获取php使用内存
3.设置与客户机断开是否会终止脚本的执行,直至有输出任务为止
ignore_user_abort(true);
4.设置默认时区与获取默认时区
date_default_timezone_set("Asia/Shanghai");
echo date_default_timezone_get();
5.设置跨域访问限制
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
crossdomain.xml跨域文件
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
6.设置报错信息
//开启报错,开发环境
error_reporting(-1);
ini_set('display_errors', 1);
//关闭报错,生产环境
ini_set('display_errors', 0);
if (version_compare(PHP_VERSION, '5.3', '>=')) {
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
} else {
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
}