Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


Line 13 is:
PHP
$xml		=	simplexml_load_file( $url );


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:
PHP
<?
	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'] ."'" );
			}
		}
	}
?>
Posted

1 solution

What i ended up doing was on script 4, downloading the selected file to a temp directory on the server, then creating a new script to pass each filename in that directory into an array using a delimiter. I then used a loop on that array to read the file still using simplexml_load_file and read the info required then deleted it.

Worked a charm :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900