CodeIgniter Forums

Full Version: SoapClient issue on CLI cron
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have created a function that call a Magento SoapClient

In traditional PHP if i run it via command php soapcron.php
it works

Also i put the same code in a function on CI, on web it Works, but on command via CLI cron it doesn't work and give me an error:

the traditional php is:


PHP Code:
$client = new SoapClient('http://www.magento.com/api/soap/?wsdl');
$session $client->login('ApiUser''ApiKey');
   try {
       $getAttributes $client->call($session'catalog_product_attribute.options'11);
   } catch (SoapFault $e) {
       echo '11';
       print($client->__getLastResponse());
   }

var_dump($getAttributes);
$client->endSession($session); 



CI Method

   
PHP Code:
 public function SyncAttributes(){

       
       $client 
= new SoapClient('http://www.magento.com/api/soap/?wsdl');
       $session $client->login('ApiUser''ApiKey');


       $attributes $this->Magento_m->getAttributes();

       foreach($attributes as $attribute){
           try {
               $getAttributes $client->call($session'catalog_product_attribute.options'$attribute->attribute_code);
           } catch (SoapFault $e) {
               echo $attribute->attribute_code;
               print($client->__getLastResponse());
           }

           foreach($getAttributes as $value){
               $dataInsert null;
               if($value['value'] != ""){
                   $dataInsert = array(
                       'attribute_code' => $attribute->attribute_code,
                       'attribute_value' => $value['value'],
                       'attribute_label' => $value['label']
                   );
               }
               if($dataInsert != null){
                   $syncronize $this->Magento_m->syncAttributes($dataInsert);
               }
           }
       }

       if(isset($syncronize) && $syncronize == true){
           echo json_encode(array('status' => 'success'));
       }else{
           echo json_encode(array('status' => 'nothing_new'));
       }

       $client->endSession($session);

   

This method is called in command php /paht/to/ci/index.php Controller SyncAttributes

the error is:

Code:
PHP Notice:  Constant ENVIRONMENT already defined in /path/to/ci/index.php on line 57

A PHP Error was encountered

Severity: Notice
Message:  Undefined offset: 2
Filename: /path/to/ci/application/controllers/Controller.php
Line Number: 25
Backtrace: File: /path/to/ci/application/controllers/Controller.php
Line: 25
Function: _error_handler
File: /path/to/ci/index.php
Line: 293
Function: require_once


A PHP Error was encountered

Severity: Error
Message:  SoapClient::SoapClient(): 'uri' option is required in nonWSDL mode
Filename: /path/to/ci/application/controllers/Controller.php
Line Number: 25



Line 25 is: $client = new SoapClient('http://www.magento.com/api/soap/?wsdl');
Is there a way to fix it?
I figured it out, being a controller under Login and the main requeriment is session, so to get data from database was required to send the request based on user and session id, so from here the fail, i checked the client and this was blank, Resolved !
For this issue: PHP Notice: Constant ENVIRONMENT already defined in /path/to/ci/index.php on line 57

I just deleted the line, and the error has gone !
(08-18-2015, 01:10 AM)arisdario Wrote: [ -> ]For this issue: PHP Notice:  Constant ENVIRONMENT already defined in /path/to/ci/index.php on line 57

I just deleted the line, and the error has gone !

Yeah, that's not a good idea. If it has already been defined, some other code must have defined it before you got to this point (which implies you're doing something strange). If you absolutely need that to be possible (and you know ENVIRONMENT will be set to a valid value), you should change it to:

PHP Code:
defined('ENVIRONMENT') OR define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');