首頁 >php教程 >PHP源码 >高性能电商平台 外贸电商系统 高负载高并发,高效,高速,分布,高性能 电商系统

高性能电商平台 外贸电商系统 高负载高并发,高效,高速,分布,高性能 电商系统

PHP中文网
PHP中文网原創
2016-05-25 17:01:521361瀏覽

高性能电商平台 外贸电商系统 高负载高并发,高效,高速,分布,高性能 电商系统
有了以下各种技术与优化,再也不为丢单而烦恼;用了此系统老板您赚钱就可高枕无忧啦!

核心特点如下:
数据库读写分离加速,memcached 缓冲加速,HTML静态页面加速

图片加水印,图片服务器分离,图片支持CDN,镜像服务器DNS轮循

多语言支持,多货币支持

订单报表统计分析,产品价格优惠处理

可灵活配置页面布局,多服务器负载均衡布局

订单批量打印,订单导出,数据分析导出,安全性高可靠性强,各种细节的优化处理

演示前台:http://demo.hecart.com/
演示后台账号:demo
演示后台密码:demo
演示后台:http://dadm.hecart.com/

网站结构采用:LINUX + NGINX + PHP + MYSQL + MEMCACHE

1. [文件]     index.php

<?php
//Version
define(&#39;VERSION&#39;, &#39;1.0.0&#39;);

//Configuration
define(&#39;DIR_SITE&#39;, empty($_SERVER[&#39;DOCUMENT_ROOT&#39;]) ? dirname(__FILE__) : $_SERVER[&#39;DOCUMENT_ROOT&#39;]);
define(&#39;DIR_ROOT&#39;, empty($_SERVER[&#39;DOCUMENT_ROOT&#39;]) ? dirname(dirname(__FILE__)) : dirname($_SERVER[&#39;DOCUMENT_ROOT&#39;]));
require(DIR_ROOT . &#39;/config/start.php&#39;); //loading start for here

//Cache OR static HTML file
if (true)
{
	//此处加速适合于多语言多货币
	$_GET[&#39;language&#39;] = wcore_utils::get_var(&#39;language&#39;, &#39;&#39;, &#39;c&#39;);
	$_GET[&#39;currency&#39;] = wcore_utils::get_var(&#39;currency&#39;, &#39;&#39;, &#39;c&#39;);
	$speed            = new wcore_speed(&#39;mem&#39;);
	unset($_GET[&#39;language&#39;], $_GET[&#39;currency&#39;]);
}
else
{
	//此处加速仅适应于单语言单货币
	$puid  = ($_SERVER["REQUEST_URI"] == &#39;/&#39; || $_SERVER["REQUEST_URI"] == $_SERVER["SCRIPT_NAME"]) ? &#39;index.html&#39; : $_SERVER["REQUEST_URI"];
	$speed = new wcore_speed(((strpos($puid, &#39;?&#39;) === false) ? &#39;file&#39; : &#39;mem&#39;), 0, $puid);
}

$html = $speed->get_data();
if (!empty($html))
{
	exit($html);
}

//Startup
require(DIR_ROOT . &#39;/system/startup.php&#39;);

//Application Classes
require(DIR_ROOT . &#39;/system/library/customer.php&#39;);
require(DIR_ROOT . &#39;/system/library/affiliate.php&#39;);
require(DIR_ROOT . &#39;/system/library/currency.php&#39;);
require(DIR_ROOT . &#39;/system/library/tax.php&#39;);
require(DIR_ROOT . &#39;/system/library/weight.php&#39;);
require(DIR_ROOT . &#39;/system/library/length.php&#39;);
require(DIR_ROOT . &#39;/system/library/cart.php&#39;);

//Registry
$registry = new Registry();

//Loader
$loader = new Loader($registry);
$registry->set(&#39;load&#39;, $loader);

//Config
$config  = new Config();
$mem_cls = new modules_mem();
$registry->set(&#39;config&#39;, $config);

$store_info = get_store_info($mem_cls);
if (empty($store_info))
{
	$config->set(&#39;config_store_id&#39;, 0);
	$config->set(&#39;config_url&#39;, &#39;http://&#39; . DOMAIN_NAME . &#39;/&#39;);
	$config->set(&#39;config_ssl&#39;, &#39;https://&#39; . DOMAIN_NAME . &#39;/&#39;);
}
else
{
	$config->set(&#39;config_store_id&#39;, $store_info[&#39;store_id&#39;]);
}

//Settings
$res = $mem_cls->mem_sql("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = " . intval($config->get(&#39;config_store_id&#39;)), DB_GET_ALL);
foreach ($res as $setting)
{
	$config->set($setting[&#39;key&#39;], ($setting[&#39;serialized&#39;]) ? unserialize($setting[&#39;value&#39;]) : $setting[&#39;value&#39;]);
}

//Url
$url = new Url($config->get(&#39;config_url&#39;), $config->get(&#39;config_use_ssl&#39;) ? $config->get(&#39;config_ssl&#39;) : $config->get(&#39;config_url&#39;));
$registry->set(&#39;url&#39;, $url);

//Log
$log = new Log($config->get(&#39;config_error_filename&#39;));
$registry->set(&#39;log&#39;, $log);

//Error Handler
function error_handler($errno, $errstr, $errfile, $errline)
{
	global $log, $config;
	switch ($errno)
	{
		case E_NOTICE:
		case E_USER_NOTICE:
			$error = &#39;Notice&#39;;
			break;
		case E_WARNING:
		case E_USER_WARNING:
			$error = &#39;Warning&#39;;
			break;
		case E_ERROR:
		case E_USER_ERROR:
			$error = &#39;Fatal Error&#39;;
			break;
		default:
			$error = &#39;Unknown&#39;;
			break;
	}

	if ($config->get(&#39;config_error_display&#39;))
	{
		echo &#39;<b>&#39; . $error . &#39;</b>: &#39; . $errstr . &#39; in <b>&#39; . $errfile . &#39;</b> on line <b>&#39; . $errline . &#39;</b>&#39;;
	}

	if ($config->get(&#39;config_error_log&#39;))
	{
		$log->write(&#39;PHP &#39; . $error . &#39;:  &#39; . $errstr . &#39; in &#39; . $errfile . &#39; on line &#39; . $errline);
	}

	return true;
}

set_error_handler(&#39;error_handler&#39;);

//Request
$request = new Request();
$registry->set(&#39;request&#39;, $request);

//Response
$response = new Response();
$response->addHeader(&#39;Content-Type: text/html; charset=utf-8&#39;);
$response->setCompression($config->get(&#39;config_compression&#39;));
$registry->set(&#39;response&#39;, $response);

//Session
$session = new wcore_session(SESSION_SAVE_TYPE);
$registry->set(&#39;session&#39;, $session);

//Language Detection
$languages = get_languages($mem_cls);
$code      = $config->get(&#39;config_language&#39;);
if (isset($request->cookie[&#39;language&#39;]) && isset($languages[$request->cookie[&#39;language&#39;]]) && $languages[$request->cookie[&#39;language&#39;]][&#39;status&#39;])
{
	$code = $request->cookie[&#39;language&#39;];
}
else //自动检测语言
{
	if (isset($request->server[&#39;HTTP_ACCEPT_LANGUAGE&#39;]) && ($request->server[&#39;HTTP_ACCEPT_LANGUAGE&#39;]))
	{
		$browser_languages = explode(&#39;,&#39;, $request->server[&#39;HTTP_ACCEPT_LANGUAGE&#39;]);
		foreach ($browser_languages as $browser_language)
		{
			foreach ($languages as $key => $value)
			{
				if ($value[&#39;status&#39;])
				{
					$locale = explode(&#39;,&#39;, $value[&#39;locale&#39;]);
					if (in_array($browser_language, $locale))
					{
						$code = $key;
					}
				}
			}
		}
	}
	$request->cookie[&#39;language&#39;] = $code;
	wcore_utils::set_cookie(&#39;language&#39;, $code, 365);
}
$config->set(&#39;config_language_id&#39;, $languages[$code][&#39;language_id&#39;]);
$config->set(&#39;config_language&#39;, $languages[$code][&#39;code&#39;]);

//Language
$language = new Language($languages[$code][&#39;directory&#39;]);
$language->load($languages[$code][&#39;filename&#39;]);
$registry->set(&#39;language&#39;, $language);

//Document
$registry->set(&#39;document&#39;, new Document());

//Customer
$registry->set(&#39;customer&#39;, new Customer($registry));

//Affiliate
$registry->set(&#39;affiliate&#39;, new Affiliate($registry));
if (isset($request->get[&#39;tracking&#39;]) && !isset($request->cookie[&#39;tracking&#39;]))
{
	wcore_utils::set_cookie(&#39;tracking&#39;, $request->get[&#39;tracking&#39;], 365);
}

//Currency
$registry->set(&#39;currency&#39;, new Currency($registry));

//Tax
$registry->set(&#39;tax&#39;, new Tax($registry));

//Weight
$registry->set(&#39;weight&#39;, new Weight($registry));

//Length
$registry->set(&#39;length&#39;, new Length($registry));

//Cart
$registry->set(&#39;cart&#39;, new Cart($registry));

//Encryption
$registry->set(&#39;encryption&#39;, new Encryption($config->get(&#39;config_encryption&#39;)));

//Front Controller
$controller = new Front($registry);

//Router
$action = new Action(isset($request->get[&#39;route&#39;]) ? $request->get[&#39;route&#39;] : &#39;common/home&#39;);

//Dispatch
$controller->dispatch($action, new Action(&#39;error/not_found&#39;));

//Output
if (defined(&#39;WCORE_SPEED&#39;))
{
	$html = $response->render();
	$speed->set_data($html);
	unset($speed);
	echo($html);
}
else
{
	$response->output();
}
?>

2. [文件]     setting.php

<?php
/**
 * 慧佳工作室 -> hoojar studio
 *
 * 模块: $Id: config.php 1 2012-11-20 05:55:12Z Administrator $
 * 简述: 网站各大参数设置 (注此文件需COPY一份到此目录下并改名为setting.php)
 * 作者: woods·zhang  ->  hoojar@163.com
 *
 * 版权 2006-2013, 慧佳工作室拥有此系统所有版权等知识产权
 * Copyright 2006-2013, Hoojar Studio All Rights Reserved.
 *
 * 设置出错等级
 */
mb_internal_encoding(&#39;UTF-8&#39;);								//系统使用默认字符集为UTF-8
ini_set(&#39;error_reporting&#39;,	E_ALL | E_STRICT);				//出错等级
ini_set(&#39;display_errors&#39;,	isset($_GET[&#39;error&#39;]) ? 1 : 1);	//是否显示出错信息0关1开
ini_set(&#39;date.timezone&#39;,	&#39;Asia/Shanghai&#39;);				//设置时区

/**
 * 执行文件的文件名与文件路径
 */
$pinfo = pathinfo($_SERVER[&#39;SCRIPT_FILENAME&#39;]);
define(&#39;EXEC_PATH&#39;,	$pinfo[&#39;dirname&#39;]);						//执行文件所在的全路径
define(&#39;EXEC_FILE&#39;,	$pinfo[&#39;basename&#39;]);					//执行文件的名称含扩展名
define(&#39;EXEC_EXT&#39;,	$pinfo[&#39;extension&#39;]);					//执行文件的扩展名
define(&#39;EXEC_NAME&#39;,	strtok(EXEC_FILE, &#39;.&#39;));				//执行文件名不含扩展名
unset($pinfo);

/**
 * 图片与JS本要加载或CDN加载开关
 */
define(&#39;USE_ISLOCAL_IMG&#39;,		0);		//是否使用本机静态文件(图片)
define(&#39;USE_ISLOCAL_JS2CSS&#39;,	1);		//是否使用本机静态文件(JS,CSS)

/**
 * 提升浏览者速度
 */
define(&#39;COMPRESS_HTML&#39;,		true);		//是否压缩HTML,为真且不出错展示关闭则对HTML进行压缩(注:如果代码写得较乱者,压缩可能会无法展示)
define(&#39;COMPRESS_JS2CSS&#39;,	true);		//是否压缩JS与CSS代码,为真且不出错展示关闭则对HTML进行压缩(注:如果代码写得较乱者,压缩可能会导致无法正常执行)

/**
 * 系统常规设置
 */
define(&#39;PRICE_ROUND&#39;,		-1);		//价格四舍五入,小于0则不4舍5入,大于等于0则4舍5入到几位小数
define(&#39;SESSION_SAVE_TYPE&#39;,	&#39;db&#39;);		//SESSION采取哪种类型与存储长度:db(max:65535) mdb(max:255) mem(max:unlimit) file(max:unlimit) dir(max:unlimit)

define(&#39;SPEED_DATA&#39;,		true);		//是否启用加速数据服务将HTML缓冲起来或生成静态文件
define(&#39;SPEED_DATA_EXPIRE&#39;,	30);		//加速数据有效期(单位分钟)

define(&#39;MEM_CACHED&#39;,		true);		//定义MEMCACHED是否有效
define(&#39;MEM_ASYN_SQL_NUM&#39;,	100);		//当异步存储了SQL条数达到此数就执行SQL

define(&#39;SQL_DEBUG&#39;,			false);		//测试SQL调试开关(true or false)
define(&#39;SQL_ERROR_FOR_TIP&#39;,	false);		//SQL语句执行出错用wcore_tip来展示

define(&#39;LOGIN_ERR_NUM&#39;,		3);			//登录出错最多可多少次后就锁帐号
define(&#39;LOGIN_PASS_HOUR&#39;,	6);			//登录出错间隔多少小时内不能登录

define(&#39;SITE_MD5_KEY&#39;,		&#39;*#6@9&#39;);	//网站MD5密匙
define(&#39;IMAGES_PATH&#39;,		&#39;/img/&#39;);	//产品图片相对于www目录而言的相对文件路径
define(&#39;DOMAIN_NAME&#39;,		isset($_SERVER[&#39;HTTP_HOST&#39;]) ? $_SERVER[&#39;HTTP_HOST&#39;] : &#39;hecart.com&#39;);//当前域名

/**
 * HTTP URL
 */
define(&#39;HTTP_STORE&#39;,	&#39;http://w.hecart.com/&#39;);		//商城HTTP主页地址
define(&#39;HTTPS_STORE&#39;,	&#39;https://w.hecart.com/&#39;);		//商城HTTPS主页地址
define(&#39;DIR_IMAGE&#39;,		DIR_ROOT . &#39;/www&#39; . IMAGES_PATH);	//商品图片存储路径

/**
 * 数据库读取类型
 */
define(&#39;DB_PREFIX&#39;,		&#39;he_&#39;);					//数据库表前缀
define(&#39;DB_GET_ONE&#39;,	&#39;fetch_one&#39;);			//获取一个数据
define(&#39;DB_GET_ROW&#39;,	&#39;fetch_row&#39;);			//获取一条数据
define(&#39;DB_GET_ALL&#39;,	&#39;fetch_all&#39;);			//获取多条数据
define(&#39;DB_GET_PAIRS&#39;,	&#39;fetch_pairs&#39;);			//获取一对数据

/**
 * 数据库主库,一般用于写入数据
 */
$db_server						= array();		//数据库服务器连接名称
$db_server[&#39;master&#39;][&#39;dbtype&#39;]	= &#39;mysqli&#39;;		//数据库连接类型
$db_server[&#39;master&#39;][&#39;host&#39;]	= &#39;localhost&#39;;	//数据库服务器主机
$db_server[&#39;master&#39;][&#39;port&#39;]	= 3306;			//数据库服务器主机端口
$db_server[&#39;master&#39;][&#39;user&#39;]	= &#39;root&#39;;		//数据库用户名
$db_server[&#39;master&#39;][&#39;pwd&#39;]		= &#39;123456&#39;;		//数据库密码
$db_server[&#39;master&#39;][&#39;dbname&#39;]	= &#39;hecart&#39;;		//数据库名
$db_server[&#39;master&#39;][&#39;charset&#39;]	= &#39;utf8&#39;;		//数据库字符集
$db_server[&#39;master&#39;][&#39;pconnect&#39;]= false;		//是否持续链接数据库

/**
 * 数据库从库,一般用于只读取数据
 */
$db_server[&#39;slave&#39;][&#39;dbtype&#39;]	= &#39;mysqli&#39;;		//数据库连接类型
$db_server[&#39;slave&#39;][&#39;host&#39;]		= &#39;localhost&#39;;	//数据库服务器主机
$db_server[&#39;slave&#39;][&#39;port&#39;]		= 3306;			//数据库服务器主机端口
$db_server[&#39;slave&#39;][&#39;user&#39;]		= &#39;root&#39;;		//数据库用户名
$db_server[&#39;slave&#39;][&#39;pwd&#39;]		= &#39;123456&#39;;		//数据库密码
$db_server[&#39;slave&#39;][&#39;dbname&#39;]	= &#39;hecart&#39;;		//数据库名
$db_server[&#39;slave&#39;][&#39;charset&#39;]	= &#39;utf8&#39;;		//数据库字符集
$db_server[&#39;slave&#39;][&#39;pconnect&#39;]	= false;		//是否持续链接数据库
define(&#39;DB_SERVERS&#39;, json_encode($db_server));
unset($db_server);

/**
 * 缓冲MEMCACHED服务器
 */
define(&#39;MEM_USE&#39;,		false);			//是否开启使用MEMCACHED服务器
define(&#39;MEM_PORT&#39;,		11211);			//MEMCACHED单机服务器端口号
define(&#39;MEM_EXPIRE&#39;,	30);			//MEMCACHED服务器存储数据的有效期,以分钟为单位
define(&#39;MEM_PREFIX&#39;,	DOMAIN_NAME);	//存储MEMCACHED数据时KEY的前缀
$mem_servers	= array();
$mem_servers[]	= &#39;127.0.0.1:11211&#39;;	//MEMCACHED服务器主机1:端口
$mem_servers[]	= &#39;127.0.0.1:11211&#39;;	//MEMCACHED服务器主机2:端口
$mem_servers[]	= &#39;127.0.0.1:11211&#39;;	//MEMCACHED服务器主机3:端口
define(&#39;MEM_SERVERS&#39;, json_encode($mem_servers));
unset($mem_servers);

/**
 * 网站图片主机域名(转换图片地址为网站实际对应的地址或CDN地址)
 */
$img_urls	= array();
$img_urls[]	= &#39;http://img1.hecart.com&#39;;	//图片主机域名1
$img_urls[]	= &#39;http://img2.hecart.com&#39;;	//图片主机域名2
$img_urls[]	= &#39;http://img3.hecart.com&#39;;	//图片主机域名3
define(&#39;IMG_URLS&#39;, json_encode($img_urls));
unset($img_urls);

/**
 * SMTP服务器
 */
$smtp_server		= array();
$smtp_server[&#39;host&#39;]= &#39;mail.hecart.com&#39;;	//SMTP服务器主机
$smtp_server[&#39;port&#39;]= 25;					//SMTP服务器端口
$smtp_server[&#39;user&#39;]= &#39;getpwd@hecart.com&#39;;	//SMTP登录用户账号
$smtp_server[&#39;upwd&#39;]= &#39;pwd!(*#489&#39;;			//SMTP登录用户密码
$smtp_server[&#39;cset&#39;]= &#39;utf-8&#39;;				//SMTP邮件内容编码
define(&#39;SMTP_SERVER&#39;, json_encode($smtp_server));
unset($smtp_server);
?>

                               

                   

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn