midrange.com code scratchpad |
Name:
Check HTTP Logic
|
Scriptlanguage:
PHP
|
Tabwidth:
4
|
Date:
06/03/2010 09:11:54 pm
|
IP:
Logged
|
|
Description:
Here is the logic. I have a LogWriter class to dump values to a long that you'll see reference here. Obviously, I am using Zend Framework to perform the HTTP request, so I suppose the problem could lie in there, but we didn't update Zend Framework. The problem just started. Only other thing missing is some constants that define the text for certain errors...but that should be pretty obvious. This was created because I have a pretty firm grasp on how the IBM and Apache2 servers relate to each other in Zend Core but others here didn't. This command runs daily and can be run manually to diagnose and issue and make a suggestion to our system administrator on how to resolve it.
|
Code:
- <?php
-
- require_once('Zend/Loader.php');
-
- Zend_Loader::loadClass('Zend_Mail');
- Zend_Loader::loadClass('Zend_Mail_Transport_Smtp');
- Zend_Loader::loadClass('Zend_Http_Client');
- Zend_Loader::loadClass('Zend_Http_Client_Adapter_Exception');
-
- $client = new Zend_Http_Client('https://www.data-management.com/php/status.php', array(
- 'maxredirects' => 0,
- 'timeout' => 30));
- */
-
- $client = new Zend_Http_Client('http://www.data-management.com/php/status.php', array(
- 'maxredirects' => 0,
- 'timeout' => 30));
-
- $client->setParameterGet('request', 'PROGRAM');
-
- $responseBody = '';
- $error = '';
- $action = '';
-
- try {
- $response = $client->request();
-
- if ($response->isSuccessful()) {
- $responseBody = $response->getBody();
- if ($responseBody == 'N') {
- $error = "Problem with PHP sever.";
- $action = ACTION_RESTARTZEND;
- }
- }
- else {
- switch ($response->getStatus()) {
- case 502 :
- $error = "Bad gateway. PHP Server not started.";
- $action = ACTION_STARTPHP;
- break;
- default :
- $error = $response->getStatus() . ': ' . $response->getMessage();
- $action = ACTION_RESTARTZEND;
- break;
- }
- }
- }
- catch(Zend_Http_Client_Adapter_Exception $err) {
-
- $response = null;
- switch ($err->getCode()) {
- case 0 :
- $error = $err->getMessage();
- $action = ACTION_STARTIBM;
- break;
- case 1000 :
- $error = "Request timed out.";
- $action = ACTION_RESTARTALL;
- break;
- default :
- $error = $err->getCode() . ': ' . $err->getMessage();
- $action = ACTION_RESTARTALL;
- break;
- }
- }
-
-
|
|
|