高性能电商平台 外贸电商系统 高负载高并发,高效,高速,分布,高性能 电商系统
有了以下各种技术与优化,再也不为丢单而烦恼;用了此系统老板您赚钱就可高枕无忧啦!
核心特点如下:
数据库读写分离加速,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('VERSION', '1.0.0'); //Configuration define('DIR_SITE', empty($_SERVER['DOCUMENT_ROOT']) ? dirname(__FILE__) : $_SERVER['DOCUMENT_ROOT']); define('DIR_ROOT', empty($_SERVER['DOCUMENT_ROOT']) ? dirname(dirname(__FILE__)) : dirname($_SERVER['DOCUMENT_ROOT'])); require(DIR_ROOT . '/config/start.php'); //loading start for here //Cache OR static HTML file if (true) { //此处加速适合于多语言多货币 $_GET['language'] = wcore_utils::get_var('language', '', 'c'); $_GET['currency'] = wcore_utils::get_var('currency', '', 'c'); $speed = new wcore_speed('mem'); unset($_GET['language'], $_GET['currency']); } else { //此处加速仅适应于单语言单货币 $puid = ($_SERVER["REQUEST_URI"] == '/' || $_SERVER["REQUEST_URI"] == $_SERVER["SCRIPT_NAME"]) ? 'index.html' : $_SERVER["REQUEST_URI"]; $speed = new wcore_speed(((strpos($puid, '?') === false) ? 'file' : 'mem'), 0, $puid); } $html = $speed->get_data(); if (!empty($html)) { exit($html); } //Startup require(DIR_ROOT . '/system/startup.php'); //Application Classes require(DIR_ROOT . '/system/library/customer.php'); require(DIR_ROOT . '/system/library/affiliate.php'); require(DIR_ROOT . '/system/library/currency.php'); require(DIR_ROOT . '/system/library/tax.php'); require(DIR_ROOT . '/system/library/weight.php'); require(DIR_ROOT . '/system/library/length.php'); require(DIR_ROOT . '/system/library/cart.php'); //Registry $registry = new Registry(); //Loader $loader = new Loader($registry); $registry->set('load', $loader); //Config $config = new Config(); $mem_cls = new modules_mem(); $registry->set('config', $config); $store_info = get_store_info($mem_cls); if (empty($store_info)) { $config->set('config_store_id', 0); $config->set('config_url', 'http://' . DOMAIN_NAME . '/'); $config->set('config_ssl', 'https://' . DOMAIN_NAME . '/'); } else { $config->set('config_store_id', $store_info['store_id']); } //Settings $res = $mem_cls->mem_sql("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = " . intval($config->get('config_store_id')), DB_GET_ALL); foreach ($res as $setting) { $config->set($setting['key'], ($setting['serialized']) ? unserialize($setting['value']) : $setting['value']); } //Url $url = new Url($config->get('config_url'), $config->get('config_use_ssl') ? $config->get('config_ssl') : $config->get('config_url')); $registry->set('url', $url); //Log $log = new Log($config->get('config_error_filename')); $registry->set('log', $log); //Error Handler function error_handler($errno, $errstr, $errfile, $errline) { global $log, $config; switch ($errno) { case E_NOTICE: case E_USER_NOTICE: $error = 'Notice'; break; case E_WARNING: case E_USER_WARNING: $error = 'Warning'; break; case E_ERROR: case E_USER_ERROR: $error = 'Fatal Error'; break; default: $error = 'Unknown'; break; } if ($config->get('config_error_display')) { echo '<b>' . $error . '</b>: ' . $errstr . ' in <b>' . $errfile . '</b> on line <b>' . $errline . '</b>'; } if ($config->get('config_error_log')) { $log->write('PHP ' . $error . ': ' . $errstr . ' in ' . $errfile . ' on line ' . $errline); } return true; } set_error_handler('error_handler'); //Request $request = new Request(); $registry->set('request', $request); //Response $response = new Response(); $response->addHeader('Content-Type: text/html; charset=utf-8'); $response->setCompression($config->get('config_compression')); $registry->set('response', $response); //Session $session = new wcore_session(SESSION_SAVE_TYPE); $registry->set('session', $session); //Language Detection $languages = get_languages($mem_cls); $code = $config->get('config_language'); if (isset($request->cookie['language']) && isset($languages[$request->cookie['language']]) && $languages[$request->cookie['language']]['status']) { $code = $request->cookie['language']; } else //自动检测语言 { if (isset($request->server['HTTP_ACCEPT_LANGUAGE']) && ($request->server['HTTP_ACCEPT_LANGUAGE'])) { $browser_languages = explode(',', $request->server['HTTP_ACCEPT_LANGUAGE']); foreach ($browser_languages as $browser_language) { foreach ($languages as $key => $value) { if ($value['status']) { $locale = explode(',', $value['locale']); if (in_array($browser_language, $locale)) { $code = $key; } } } } } $request->cookie['language'] = $code; wcore_utils::set_cookie('language', $code, 365); } $config->set('config_language_id', $languages[$code]['language_id']); $config->set('config_language', $languages[$code]['code']); //Language $language = new Language($languages[$code]['directory']); $language->load($languages[$code]['filename']); $registry->set('language', $language); //Document $registry->set('document', new Document()); //Customer $registry->set('customer', new Customer($registry)); //Affiliate $registry->set('affiliate', new Affiliate($registry)); if (isset($request->get['tracking']) && !isset($request->cookie['tracking'])) { wcore_utils::set_cookie('tracking', $request->get['tracking'], 365); } //Currency $registry->set('currency', new Currency($registry)); //Tax $registry->set('tax', new Tax($registry)); //Weight $registry->set('weight', new Weight($registry)); //Length $registry->set('length', new Length($registry)); //Cart $registry->set('cart', new Cart($registry)); //Encryption $registry->set('encryption', new Encryption($config->get('config_encryption'))); //Front Controller $controller = new Front($registry); //Router $action = new Action(isset($request->get['route']) ? $request->get['route'] : 'common/home'); //Dispatch $controller->dispatch($action, new Action('error/not_found')); //Output if (defined('WCORE_SPEED')) { $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 -> [email protected] * * 版权 2006-2013, 慧佳工作室拥有此系统所有版权等知识产权 * Copyright 2006-2013, Hoojar Studio All Rights Reserved. * * 设置出错等级 */ mb_internal_encoding('UTF-8'); //系统使用默认字符集为UTF-8 ini_set('error_reporting', E_ALL | E_STRICT); //出错等级 ini_set('display_errors', isset($_GET['error']) ? 1 : 1); //是否显示出错信息0关1开 ini_set('date.timezone', 'Asia/Shanghai'); //设置时区 /** * 执行文件的文件名与文件路径 */ $pinfo = pathinfo($_SERVER['SCRIPT_FILENAME']); define('EXEC_PATH', $pinfo['dirname']); //执行文件所在的全路径 define('EXEC_FILE', $pinfo['basename']); //执行文件的名称含扩展名 define('EXEC_EXT', $pinfo['extension']); //执行文件的扩展名 define('EXEC_NAME', strtok(EXEC_FILE, '.')); //执行文件名不含扩展名 unset($pinfo); /** * 图片与JS本要加载或CDN加载开关 */ define('USE_ISLOCAL_IMG', 0); //是否使用本机静态文件(图片) define('USE_ISLOCAL_JS2CSS', 1); //是否使用本机静态文件(JS,CSS) /** * 提升浏览者速度 */ define('COMPRESS_HTML', true); //是否压缩HTML,为真且不出错展示关闭则对HTML进行压缩(注:如果代码写得较乱者,压缩可能会无法展示) define('COMPRESS_JS2CSS', true); //是否压缩JS与CSS代码,为真且不出错展示关闭则对HTML进行压缩(注:如果代码写得较乱者,压缩可能会导致无法正常执行) /** * 系统常规设置 */ define('PRICE_ROUND', -1); //价格四舍五入,小于0则不4舍5入,大于等于0则4舍5入到几位小数 define('SESSION_SAVE_TYPE', 'db'); //SESSION采取哪种类型与存储长度:db(max:65535) mdb(max:255) mem(max:unlimit) file(max:unlimit) dir(max:unlimit) define('SPEED_DATA', true); //是否启用加速数据服务将HTML缓冲起来或生成静态文件 define('SPEED_DATA_EXPIRE', 30); //加速数据有效期(单位分钟) define('MEM_CACHED', true); //定义MEMCACHED是否有效 define('MEM_ASYN_SQL_NUM', 100); //当异步存储了SQL条数达到此数就执行SQL define('SQL_DEBUG', false); //测试SQL调试开关(true or false) define('SQL_ERROR_FOR_TIP', false); //SQL语句执行出错用wcore_tip来展示 define('LOGIN_ERR_NUM', 3); //登录出错最多可多少次后就锁帐号 define('LOGIN_PASS_HOUR', 6); //登录出错间隔多少小时内不能登录 define('SITE_MD5_KEY', '*#6@9'); //网站MD5密匙 define('IMAGES_PATH', '/img/'); //产品图片相对于www目录而言的相对文件路径 define('DOMAIN_NAME', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'hecart.com');//当前域名 /** * HTTP URL */ define('HTTP_STORE', 'http://w.hecart.com/'); //商城HTTP主页地址 define('HTTPS_STORE', 'https://w.hecart.com/'); //商城HTTPS主页地址 define('DIR_IMAGE', DIR_ROOT . '/www' . IMAGES_PATH); //商品图片存储路径 /** * 数据库读取类型 */ define('DB_PREFIX', 'he_'); //数据库表前缀 define('DB_GET_ONE', 'fetch_one'); //获取一个数据 define('DB_GET_ROW', 'fetch_row'); //获取一条数据 define('DB_GET_ALL', 'fetch_all'); //获取多条数据 define('DB_GET_PAIRS', 'fetch_pairs'); //获取一对数据 /** * 数据库主库,一般用于写入数据 */ $db_server = array(); //数据库服务器连接名称 $db_server['master']['dbtype'] = 'mysqli'; //数据库连接类型 $db_server['master']['host'] = 'localhost'; //数据库服务器主机 $db_server['master']['port'] = 3306; //数据库服务器主机端口 $db_server['master']['user'] = 'root'; //数据库用户名 $db_server['master']['pwd'] = '123456'; //数据库密码 $db_server['master']['dbname'] = 'hecart'; //数据库名 $db_server['master']['charset'] = 'utf8'; //数据库字符集 $db_server['master']['pconnect']= false; //是否持续链接数据库 /** * 数据库从库,一般用于只读取数据 */ $db_server['slave']['dbtype'] = 'mysqli'; //数据库连接类型 $db_server['slave']['host'] = 'localhost'; //数据库服务器主机 $db_server['slave']['port'] = 3306; //数据库服务器主机端口 $db_server['slave']['user'] = 'root'; //数据库用户名 $db_server['slave']['pwd'] = '123456'; //数据库密码 $db_server['slave']['dbname'] = 'hecart'; //数据库名 $db_server['slave']['charset'] = 'utf8'; //数据库字符集 $db_server['slave']['pconnect'] = false; //是否持续链接数据库 define('DB_SERVERS', json_encode($db_server)); unset($db_server); /** * 缓冲MEMCACHED服务器 */ define('MEM_USE', false); //是否开启使用MEMCACHED服务器 define('MEM_PORT', 11211); //MEMCACHED单机服务器端口号 define('MEM_EXPIRE', 30); //MEMCACHED服务器存储数据的有效期,以分钟为单位 define('MEM_PREFIX', DOMAIN_NAME); //存储MEMCACHED数据时KEY的前缀 $mem_servers = array(); $mem_servers[] = '127.0.0.1:11211'; //MEMCACHED服务器主机1:端口 $mem_servers[] = '127.0.0.1:11211'; //MEMCACHED服务器主机2:端口 $mem_servers[] = '127.0.0.1:11211'; //MEMCACHED服务器主机3:端口 define('MEM_SERVERS', json_encode($mem_servers)); unset($mem_servers); /** * 网站图片主机域名(转换图片地址为网站实际对应的地址或CDN地址) */ $img_urls = array(); $img_urls[] = 'http://img1.hecart.com'; //图片主机域名1 $img_urls[] = 'http://img2.hecart.com'; //图片主机域名2 $img_urls[] = 'http://img3.hecart.com'; //图片主机域名3 define('IMG_URLS', json_encode($img_urls)); unset($img_urls); /** * SMTP服务器 */ $smtp_server = array(); $smtp_server['host']= 'mail.hecart.com'; //SMTP服务器主机 $smtp_server['port']= 25; //SMTP服务器端口 $smtp_server['user']= '[email protected]'; //SMTP登录用户账号 $smtp_server['upwd']= 'pwd!(*#489'; //SMTP登录用户密码 $smtp_server['cset']= 'utf-8'; //SMTP邮件内容编码 define('SMTP_SERVER', json_encode($smtp_server)); unset($smtp_server); ?>
登录后复制