Welcome Guest, Not a member yet? Register   Sign In
PHP 4 try-catch
#1

[eluser]FuzzyJared[/eluser]
I have developed a FedexAPI class within a PHP 5 environment, but the host is currently running PHP 4. So the try catch function breaks under PHP 4. I have looked on the web for alternatives, but have not found one that is really applicable. Any suggestions would be helpful!
Code:
try {
            $response = $client ->__soapCall("getRate", array('parameters' => $request));

            if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
            {
                return $response->RatedShipmentDetails->ShipmentRateDetail->TotalNetCharge->Amount;
                return returnRequestResponse($client);
            }
            else
            {
                echo 'Error in processing transaction.'. $newline. $newline;
                foreach ($response -> Notifications as $notification)
                {          
                    if(is_array($response -> Notifications))
                    {              
                       echo $notification -> Severity;
                       echo ': ';          
                       echo $notification -> Message . $newline;
                    }
                    else
                    {
                        echo $notification . $newline;
                    }
                }
                $this->_writeToLog($client);    // Write to log file
                //return $return;
                return '';
                
            }

            

        } catch (SoapFault $exception) {
            $this->printFault($exception, $client);
}
#2

[eluser]FuzzyJared[/eluser]
I was able to find this, but have not been able to get it working with my example as of yet.
Code:
<?php
$client = new SoapClient("some.wsdl", array('exceptions' => 0));
$result = $client->SomeFunction();
if (is_soap_fault($result)) {
    trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
}
?>
#3

[eluser]FuzzyJared[/eluser]
I could have avoided this by using nusoap instead of the PHP SOAP calls. This doesn't use try { } catch { } within the code.


http://ellislab.com/forums/viewthread/66603/
#4

[eluser]CI jforth[/eluser]
I just wrote a Fedex tracking and rates class that uses curl instead of soap works great. I'll see about putting posting it on the wiki.
#5

[eluser]devain[/eluser]
can you post your fedex code and class for some reason I cannot get what I have working with soap
#6

[eluser]FuzzyJared[/eluser]
http://ellislab.com/forums/viewthread/66603/

that is the thread for what I was able to get working in nusoap.
#7

[eluser]devain[/eluser]
Basic Tracking


Thanks for the reply I am trying to do the tracking part of a package and I get the following error

HTTP
Could not connect to host

here is the code that I am using and like yours it came from the fedex site.

track.php file
eyeglasses123.com/track.php
Code:
<?PHP

require_once('fedex-common.php5');

$newline = "<br />";
$path_to_wsdl = "TrackService_v2.wsdl";

ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array('UserCredential' =>
                                                      array('Key' => 'Nu7mKVoi6CruG3BH', 'Password' => '2WTI0OChPx1U7yprVqjosFpM7')); // Replace 'XXX' and 'YYY' with FedEx provided credentials
$request['ClientDetail'] = array('AccountNumber' => '510087542', 'MeterNumber' => '1220784');// Replace 'XXX' with your account and meter number
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Track Request v2 using PHP ***');
$request['Version'] = array('ServiceId' => 'trck', 'Major' => '2', 'Intermediate' => '0', 'Minor' => '0');
$request['PackageIdentifier'] = array('Value' => '99999999999', // Replace with a valid tracking identifier
                                      'Type' => 'TRACKING_NUMBER_OR_DOORTAG');
$request['IncludeDetailedScans'] = 1;

try
{
$response = $client ->track($request);
    

    if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
    {
        foreach ($response -> TrackDetails -> Events as $event)
        {
            if(is_array($response -> TrackDetails -> Events))
            {              
               echo $event -> Timestamp . ':  ';
               echo $event -> EventDescription . ' - ';
               echo $event -> Address -> City . ' ';
               echo $event -> Address -> StateOrProvinceCode . $newline;
            }
            else
            {
                echo $location . $newline;
            }
        }
        printRequestResponse($client);
    }
    else
    {
        echo 'Error in processing transaction.'. $newline. $newline;
        foreach ($response -> Notifications as $notification)
        {
            if(is_array($response -> Notifications))
            {              
               echo $notification -> Severity;
               echo ': ';          
               echo $notification -> Message . $newline;
            }
            else
            {
                echo $notification . $newline;
            }
        }
    }
    
    writeToLog($client);    // Write to log file  

} catch (SoapFault $exception) {
    printFault($exception, $client);
}
    
?&gt;

log file
eyeglasses123.com/fedextransaction.log


Here is the wsdl

eyeglasses123.com/TrackService_v2.wsdl


last file is the fedex-common.php5

Code:
&lt;?php

define('TRANSACTIONS_LOG_FILE', 'fedextransactions.log');  // Transactions log file

/**
*  Print SOAP request and response
*/
function printRequestResponse($client) {
  echo '<h2>Transaction processed successfully.</h2>'. "\n";
  echo '<h2>Request</h2>' . "\n";
  echo '<pre>' . htmlspecialchars($client->__getLastRequest()). '</pre>';  
  echo "\n";
  
  echo '<h2>Response</h2>'. "\n";
  echo '<pre>' . htmlspecialchars($client->__getLastResponse()). '</pre>';
  echo "\n";
}

/**
*  Print SOAP Fault
*/  
function printFault($exception, $client) {
    echo '<h2>Fault</h2>' . "\n";                        
    echo "<b>Code:</b>{$exception->faultcode}<br>\n";
    echo "<b>String:</b>{$exception->faultstring}<br>\n";
    writeToLog($client);
}

/**
* SOAP request/response logging to a file
*/                                  
function writeToLog($client){  
if (!$logfile = fopen(TRANSACTIONS_LOG_FILE, "a"))
{
   error_func("Cannot open " . TRANSACTIONS_LOG_FILE . " file.\n", 0);
   exit(1);
}

fwrite($logfile, sprintf("\r%s:- %s",date("D M j G:i:s T Y"), $client->__getLastRequest(). "\n\n" . $client->__getLastResponse()));
}

?&gt;


If you goto the link eyeglasses123.com/track.php you will see that I get the following error

Fault
Code:HTTP
String:Could not connect to host


I am wondering what I am doing wrong and why this is not working this is installed with regular soap. I would appericate any help on this
#8

[eluser]devain[/eluser]
this is the actual error I seem to be getting


Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /home/eye123/public_html/track.php:44 Stack trace: #0 [internal function]: SoapClient->__doRequest('&lt;?xml version="...', 'https://gateway...', 'track', 1, 0) #1 [internal function]: SoapClient->__call('track', Array) #2 /home/eye123/public_html/track.php(44): SoapClient->track(Array) #3 {main} thrown in /home/eye123/public_html/track.php on line 44
#9

[eluser]devain[/eluser]
By the way thanks everyone for the help with this After removing the generic error codes I came up with this error

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /home/eye123/public_html/track.php:44 Stack trace: #0 [internal function]: SoapClient->__doRequest(’&lt;?xml version=”...’, ‘https://gateway...’, ‘track’, 1, 0) #1 [internal function]: SoapClient->__call(’track’, Array) #2 /home/eye123/public_html/track.php(44): SoapClient->track(Array) #3 {main} thrown in /home/eye123/public_html/track.php on line 44



Then after a couple of days of trying to figure out what this error was and trying different soap call constructs I decided that it was not the code and turned to my soap install After recompiling soap with the following below I got everything to work


So thanks everyone for the help and input


--enable-soap' '--enable-sockets' '--enable-wddx' '--

soap
Soap Client enabled
Soap Server enabled

Directive Local Value Master Value
soap.wsdl_cache 1 1
soap.wsdl_cache_dir /tmp /tmp
soap.wsdl_cache_enabled 1 1
soap.wsdl_cache_limit 5 5
soap.wsdl_cache_ttl 86400 86400




Theme © iAndrew 2016 - Forum software by © MyBB