本文介绍了PHP脚本,可能崩溃 - 错误500?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些附带API的备份软件。我正在尝试用PHP编写一个小型报告站点,供员工用来密切备份。为了速度原因,我编写了每5分钟自动编写的脚本并将信息写入MySqlDB。然后该站点读取数据库,而不是每次都从服务器提取实时统计数据,使其非常慢。



第一个脚本提取所有用户和配额等。 。

第二个脚本循环所有用户并提取他们拥有的备份集。

第三个脚本循环所有备份集并提取备份作业。



EG

1)CodeProject(第一位用户)

2)Exchange Server(BackupSet)

3 )2015-04-20-18-00-00(备份工作一)

4)2015-04-21-18-00-00(备份工作二)



上述3个完美无缺。但是第三个脚本插入了26,756行。因此,脚本4将轮询所有26,756行,并使用simplexml_load_file PHP API传递XML。然而,大约10分钟后,它只是停止并给出500 - 内部服务器错误。其中一些确实运行,我可以看到我期待的数据库中的条目,所以我知道它最好去。我不明白为什么它在崩溃时正在做,并且非常感谢一些帮助!



PHP错误日志显示了几个警告,但我不认为它需要担心的事情:



I have some backup software that comes with API's included. I'm trying to write a small reporting site in PHP for staff to use to keep an eye on backups. To do so for speed reasons, i've written scripts that are automated every 5 minutes and write the info into a MySqlDB. The site then reads the DB rather than having to pull live stats from teh server everytime making it very slow.

The first script pulls all the users and quota's etc...
The second script loops all users and pulls the backup sets they have.
The third script loops all backup sets and pulls the backup jobs.

E.G.
1) CodeProject (First User)
2) Exchange Server (BackupSet)
3) 2015-04-20-18-00-00 (Backup Job One)
4) 2015-04-21-18-00-00 (Backup Job Two)

The above 3 work perfectly with no issues. However the third script inserts 26,756 rows. So script 4 will poll all 26,756 rows and pass the XML using simplexml_load_file PHP API. However after around 10 minutes it just stops and gives a 500 - INTERNAL SERVER ERROR. Some of it does run and i can see entries into the DB that i am expecting, so i know it's mostly good to go. I can't see why it's doing when it crashes and would really appreciate some help please!

PHP Error Log shows a couple of warnings, but i don't think its anything to worry about:

[20-Apr-2015 10:07:08 Europe/Dublin] PHP Warning:  simplexml_load_file(): parser error : xmlParseCharRef: invalid xmlChar value 22 in C:\inetpub\Websites\NewSite\4 - GetBackupJobsStatus.php on line 13
[20-Apr-2015 10:07:08 Europe/Dublin] PHP Warning:  simplexml_load_file(): p="2014-05-05 21:21:08" Message="[com.ahsay.afc.microsoft.MSExchangeExpt]  in 4 - GetBackupJobsStatus.php on line 13
[20-Apr-2015 10:07:08 Europe/Dublin] PHP Warning:  simplexml_load_file():                                                                                ^ in 4 - GetBackupJobsStatus.php on line 13





第13行是:



Line 13 is:

$xml		=	simplexml_load_file( $url );





注意:我甚至尝试过将脚本的后半部分分成单独的脚本并使用curl调用它,可能运行另一个脚本26,756次!那仍然失败。



下面的脚本:



Note: I've even tried the later part of the script into a seperate script and used curl to call it, potentially running another script 26,756 times! That still failed.

Script below:

<?
	set_time_limit( -1 );

	if( mysql_connect( "localhost", "root", "ROOT_PASSWORD" ) )
	{
		if( mysql_select_db( "backupstate" ) )
		{
			$JobStatusQuery	=	mysql_query( "SELECT `clientname`,`backupset`,`backupjob` FROM `backupjobs`" );
			while( $row = mysql_fetch_assoc( $JobStatusQuery ) )
			{
				$url		=	"http://BACKUPSERVER_LINK/GetBackupJobReport.do?LoginName=". $row['clientname'] ."&BackupSetID=". $row['backupset'] ."&BackupJobID=". $row['backupjob'] ."&SysUser=admin&SysPwd=BACKUPSERVER_PASSWORD";
				$xml		=	simplexml_load_file( $url );  //500 Internal Server Error. Comment out and it runs.
				$Status		=	"";
				$Message	=	"";

				if( !strcmp( $xml['BackupJobStatus'], "BS_STOP_SUCCESS" ) )
					$Status = "Successful";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_STOP_BY_SYSTEM_ERROR" ) )
					$Status = "System Error";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_STOP_BY_SCHEDULER" ) )
					$Status = "Stopped by scheduler";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_STOP_BY_QUOTA_EXCEEDED" ) )
					$Status = "Quota Exceeded";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_STOP_MISSED_BACKUP" ) )
					$Status = "Backup missed";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_BACKUP_NOT_FINISHED" ) )
					$Status = "Still Running";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_STILL_RUNNING" ) )
					$Status = "Still Running";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_MISSED_DATABASAE" ) )
					$Status = "Missed a database";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_MISSED_PUBLIC_FOLDER" )	)
					$Status = "Missed a public folder";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_MISSED_VIRTUAL_MACHINE" ) )
					$Status = "Missed a virtual machine";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_STOP_SUCCESS_WITH_WARNING" ) )
					$Status = "Successful with warnings";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_STOP_SUCCESS_WITH_ERROR" ) )
					$Status = "Successful with errors";
				else if( !strcmp( $xml['BackupJobStatus'], "BS_STOP_BY_USER" ) )
					$Status = "User cancelled";
				else
					$Status = $xml['BackupJobStatus'];

				if( $xml && $xml->Info )
				{
					foreach( $xml->Info as $BackupMessage )
					{
						$Message .= $BackupMessage['Message'] . "</br>";
					}
				}

				mysql_query( "UPDATE `backupjobs` SET `status` = '". addslashes( $Status ) ."', `message` = '". addslashes( $Message ) ."' WHERE `clientname` = '". $row['clientname'] ."' AND `backupset` = '". $row['backupset'] ."' AND `backupjob` = '". $row['backupjob'] ."'" );
			}
		}
	}
?>

推荐答案






注意:我甚至尝试将脚本的后面部分编写成单独的脚本并使用curl来调用它,可能运行另一个脚本26,756次!那仍然失败。



下面的脚本:



Note: I've even tried the later part of the script into a seperate script and used curl to call it, potentially running another script 26,756 times! That still failed.

Script below:

<?
	set_time_limit( -1 );

	if( mysql_connect( "localhost", "root", "ROOT_PASSWORD" ) )
	{
		if( mysql_select_db( "backupstate" ) )
		{
			



这篇关于PHP脚本,可能崩溃 - 错误500?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 00:14