asp代替php,关于从经典ASP到PHP的迁移:从经典ASP到PHP的迁移-本地资源与实时资源...

我正在评估将一个相当大的站点从Classic ASP迁移到PHP,当然,我首先要研究所有潜在的问题和速度障碍。 PHP版本最初仍将在IIS下运行。

开发涉及一个本地mySQL服务器和一些本地域,例如localhost.website.com,localhost.cdn.website.com,localhost.api.website.com等,但是实时系统不使用它们,而仅使用实时域等。

目前,在经典ASP中,系统通过使用仅在服务器上存在的信号量文件在"实时"和"开发"之间切换。它在global.asa中执行此操作,然后根据文件的存在来设置一堆应用程序变量。

我对PHP不是特别熟悉,但是环顾四周似乎似乎在遵循"不共享"原则,因此没有"应用程序范围"的东西。

我想知道如何实现一个类似的环境,在该环境中无需更改就可以在本地上传代码,并且系统可以有效地自动识别它所在的系统。

主机名检查,配置文件等...相同的基本概念,不同的实现。

您能否详细说明一个答案。 我确实说过我不熟悉PHP。

您将创建一个config.php文件,在其中设置一堆变量,然后将其包含在所有PHP脚本的顶部以将设置携带到其中。 您还可以滥用APC进行某些应用程序特定的设置。 us1.php.net/manual/en/book.apc.php

谢谢。 APC看起来很有用,因为此刻我们查询数据库并将一堆相当静态的内容加载到ASP Application对象中。 APC可以以我认为的相同方式使用。

过去,我们已经成功使用了此技术:

DevLevel.0代表生产,DevLevel.1代表登台,DevLevel.2代表开发。我们有一个PHP全局包含,检查__FILE__魔术常数,查看我们所处的位置,然后相应地设置DevLevel常数。然后在各个地方,我们将拥有:

if(DevLevel == 0)

run credit card in live mode;

else

run credit card in test mode;

但是,问题在于我们超过了它。有时,站点具有2个暂存位置和10个开发位置,两者之间存在细微的差异。

从那时起,我们开发了一个自动脚本,该脚本可以检查环境并在项目中发出Local.php,而不受版本控制。它非常灵活,可以让我们使用一个命令在任何环境中自动生成apache,nginx,mysql,postgresql,redis,ssl和项目配置。

但是回到您的项目。这是我的建议:

/path/to/project/conf/example-local.php

/path/to/project/conf/local.php

/path/to/project/conf/.gitignore (contents: local.php)

(用SCM系统使用的任何忽略机制替换gitignore)

在example-local.php中放置一个"示例"配置。然后,开发人员或发行工程师每次签出副本时,只需将example-local.php复制到local.php并进行调整即可。

您的应用程序应该具有一个全局包含文件(例如global.php),该文件首先在每个脚本PERIOD中包含。它应依次包含local.php,然后验证是否定义了正确的常量并且有效。

这是global.php的片段

///

define('App_Path', dirname(dirname(__FILE__)));

define('CORE_PATH', App_Path.'/Web/');

ini_set("max_execution_time","0");

// For the purposes of including pear embedded in the application

set_include_path(App_Path . '/PHP/pear' . PATH_SEPARATOR . get_include_path() );

require_once(App_Path ."/AutoConf/Local.php");

///

// Utility function to assert that a constant has been defined.

function DefinedOrDie($constant, $message)

{

if(! defined($constant))

die("Constant '$constant' not defined in site configuration. $message");

}

// Utility function to check if a constant is defined, and if not, define it.

function DefinedOrDefault($constant, $default)

{

if(! defined($constant))

define($constant, $default);

}

/

// These are the constants which MUST be defined in the AutoConf file

DefinedOrDie('DevLevel',"DevelopmentLevel.  0=Production, 1=Preview, 2=Devel.");

if(DevLevel !== 0 && DevLevel !== 1 && DevLevel !== 2)

die("DevLevel constant must be defined as one of [0, 1, 2].");

DefinedOrDie('DEFAULT_HOSTNAME',"Canonical hostname of the site.  No trailing slash or leading protocol!");

DefinedOrDie('DB_HOST',"Database server hostname.");

DefinedOrDie('DB_NAME',"Database name.");

DefinedOrDie('DB_USER',"Database login username.");

DefinedOrDie('DB_PASS',"Database password.");

if(DevLevel > 0){

DefinedOrDie('Email_OnlySendIfMatch',"Preg regex email must match to be sent.");

DefinedOrDie('Email_OverrideAddress',"Email address to send all emails to.");

DefinedOrDie('Fax_OnlySendIfMatch',"Preg regex fax number must match to be sent.");

DefinedOrDie('Fax_OverrideNumber',"Fax number to send all faxes to.");

DefinedOrDie('Text_OnlySendIfMatch',"Preg regex text message must match to be sent.");

DefinedOrDie('Text_OverrideNumber',"Text number to send all texts to.");

DefinedOrDie('Phone_OnlySendIfMatch',"Preg regex phone number must match to be sent.");

DefinedOrDie('Phone_OverrideNumber',"Phone number to place all phone calls to.");

DefinedOrDefault('PROCESS_BILLING', false);

DefinedOrDefault('MEMCACHE_ENABLED', false);

}else{

DefinedOrDefault('PROCESS_BILLING', true);

DefinedOrDefault('MEMCACHE_ENABLED', true);

}

///

// These are the constants which MAY be defined in the AutoConf file

// Default settings for live site

if(DevLevel == 0)

{

define('DEVEL', false);

define('DEVEL_DEBUG', false);

error_reporting (E_RECOVERABLE_ERROR | E_ERROR | E_PARSE);

ini_set("display_errors", false);

}

// Default settings for preview site

elseif(DevLevel == 1)

{

define('DEVEL', true);

define('DEVEL_DEBUG', false);

error_reporting (E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);

ini_set("display_errors", true);

}

// Default settings for development and other sites

else

{

// TODO: remove E_DEPRECATED, and take care of all warnings

define('DEVEL', true);

define('DEVEL_DEBUG', false);

error_reporting (E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);

ini_set("display_errors", true);

}

// Memcache settings are required, here are defaults

DefinedOrDefault('MEMCACHE_HOST', 'localhost');

DefinedOrDefault('MEMCACHE_PORT', '11211');

这是一个更复杂(但匹配)的local.php的示例

define('DevLevel', 1);

define('DB_HOST', 'localhost');

define('DB_NAME', '*******');

define('DB_USER', '*******');

define('DB_PASS', '*******');

define('DEFAULT_HOSTNAME', '***********');

define('MEMCACHE_SESSION_HOST', 'localhost');

//define users who will be notified when different alerts are sent by the system. Separate users with a |

define('ALERT_LEVEL_NOTICE_SMS', '122342342319');

define('ALERT_LEVEL_NOTICE_EMAIL', 'j3@example.com');

define('PROCESS_BILLING', false);

define('Email_OnlySendIfMatch', '/(appcove.com|example.com)$/');

define('Email_OverrideAddress', false);

define('FAXES_LIVE', true); //false to use phaxio's test keys (no faxes are sent)

function HN_LiveToDev($host){

return str_replace('.', '--', $host).'.e1.example.net';

}

function HN_DevToLive($host){

$count = 0;

$host = str_replace('.e1.example.net', '', $host, $count);

if($count > 0){

return str_replace('--', '.', $host);

}else{

die('URL does not look like a dev URL. Could not translate DevToLive.');

}

}

谢谢,太好了! 由于我们只有几个开发人员在从事此工作,因此很容易坚持相同的文件夹结构和数据库访问权限,因此,无论是现场开发还是开发(可能是测试/登台)都非常简单。

我不熟悉IIS,但是在apache上,我已经让网络服务器仅在我的开发箱网络服务器配置中设置了环境变量。然后在php中:

define('DEV', isset($_ENV['my_env_var']));

这比检查文件要快,因为从来没有任何IO。它还具有理想的属性,即在没有环境变量的情况下默认为"实时"模式。

$_ENV是预定义的变量:http://php.net/manual/zh/reserved.variables.php

当心-在php中,未定义的常量将解释为未引用的字符串,并将强制转换为布尔值true。只要确保常量总是被定义就可以了。

谢谢,我不了解_ENV,它使我无法自拔。 我想我可以使用$ _SERVER [SERVER_NAME]配置正确的数据库等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值