0 Replies Latest reply on Feb 11, 2013 3:15 PM by Vaibhav Bhasin

    Flex and Zend amf deployment resolved with proper solution

    Vaibhav Bhasin Level 1

      Hi All,

       

      Although, I personally do not like using Zend for these issues itself. However, I faced this issue first time with flex 4.0 version when everyone used to run into

      channel disconnected error. you can find the link for that post here:

      http://forums.adobe.com/message/3366991.

       

      Now, with flash builder 4.6, things have changed slightly and so the deployment process. So, here are the right set of steps to be followed :

       

      1. after developing your flash project, export the release build(I assume if you are a flex user, you should know these steps already)

      2. Now, check your release folder, you must have got some files with amfconfig.ini and gateway.php and just one folder named history.

      3. copy all these files into a new folder say "My Release Build".

      4. Now, step 1 is get Zend framework in place, to achieve that:

      there are different ways. some will say : "make sure zend must already installed on your production server." that is an alternative but most likely,  the easier way to do this is : search your www(root folder on localhost),you will find a folder with name ZendFramework. Copy this folder to "My Release Build"

       

      5. Now, the services that you have used in your flex project, go to debug folder of your project which should be in your www(root folder on localhost) with name "yourprojectname-debug". copy services folder from this debug folder to "My Release Build"

       

      6. Now, open your amfconfig.ini from "My Release Build" and edit and make it look like following:

       

      [zend]

      webroot = http://www.yourwebsite.com

      ;you can edit above webroot to match the root folder of your website or use . to make it point to root.

       

      zend_path = ./ZendFramework/library

       

      [zendamf]

      amf.production = true

      amf.directories[]= services

       

      thats it. your amf config is fine.

       

      7. edit gateway.php:

       

      Now, remove everything from gateway.php and copy this as it is there:

       

      <?php

      ini_set("display_errors", 1);

      $dir = '.';

      $webroot = $_SERVER['DOCUMENT_ROOT'];

      $configfile = "amf_config.ini";

       

      //default zend install directory

      $zenddir = $webroot. '/ZendFramework/library';

       

      //Load ini file and locate zend directory

      if(file_exists($configfile)) {

          $arr=parse_ini_file($configfile,true);

          if(isset($arr['zend']['webroot'])){

              $webroot = $arr['zend']['webroot'];

              $zenddir = $webroot. '/ZendFramework/library';

          }

          if(isset($arr['zend']['zend_path'])){

              $zenddir = $arr['zend']['zend_path'];

          }

      }

      // Setup include path

          //add zend directory to include path

      set_include_path(get_include_path().PATH_SEPARATOR.$zenddir);

      // Initialize Zend Framework loader

      require_once 'Zend/Loader/Autoloader.php';

      Zend_Loader_Autoloader::getInstance();

      // Load configuration

      $default_config = new Zend_Config(array("production" => false), true);

      $default_config->merge(new Zend_Config_Ini($configfile, 'zendamf'));

      $default_config->setReadOnly();

      $amf = $default_config->amf;

       

      // Store configuration in the registry

      Zend_Registry::set("amf-config", $amf);

      // Initialize AMF Server

      $server = new Zend_Amf_Server();

       

      $server->setProduction($amf->production);

       

      if(isset($amf->directories)) {

          $dirs = $amf->directories->toArray();

          foreach($dirs as $dir) {

              // get the first character of the path.

              // If it does not start with slash then it implies that the path is relative to webroot. Else it will be treated as absolute path

              $length = strlen($dir);

              $firstChar = $dir;

              if($length >= 1)

                  $firstChar = $dir[0];

             

              if($firstChar != "/"){

                  // if the directory is ./ path then we add the webroot only.

                  if($dir == "./"){               

                      $server->addDirectory($webroot);

                  }else{

                      $tempPath = $webroot . "/" . $dir;

                      $server->addDirectory($tempPath);

                  }       

              }else{

                     $server->addDirectory($dir);           

              }

          }

      }

      // Initialize introspector for non-production

      if(!$amf->production) {

          $server->setClass('Zend_Amf_Adobe_Introspector', '', array("config" => $default_config, "server" => $server));

          $server->setClass('Zend_Amf_Adobe_DbInspector', '', array("config" => $default_config, "server" => $server));

      }

      // Handle request

      echo $server->handle();

       

      Now, upload your "My Release Build folder to your production server webroot"

       

       

      case 1: if you get "channel disconnected error, you have made some mistake and your path for zend or services folder is not right."

      In above case, "ZendFramework folder and services folder with all of other release files". To find out what is wrong, open this url :

       

      http://www.yourwebsite.com/gateway.php. if you see this lovely string there : "Zend Amf Endpoint". consider your are through with zend settings on server

      otherwse you will see relative errors.

       

      2. After fixing this step, try run your website, you will land into this error :

      Class “yourcorrectclassname” does not exist: Plugin by name ‘Classname’ was not found in the registry; used paths:

      : /home1/messoftc/public_html/oc/services/

      #0 /home1/messoftc/public_html/ZendFramework/library/Zend/Amf/Server.php(553): Zend_Amf_Server->_dispatch(‘fxnname’, Array, ‘classname’)

      #1 /home1/messoftc/public_html/ZendFramework/library/Zend/Amf/Server.php(629): Zend_Amf_Server->_handle(Object(Zend_Amf_Request_Http))

      #2 /home1/messoftc/public_html/oc/gateway.php(69): Zend_Amf_Server->handle()

      #3 {main}

       

       

      Now, this is a zend framework bug, it does not automatically detect the php classes in your services folder,those who have run into this, must have googled hard to find the solution and this bug is also logged officially on zend server jira log.

      so, what is the solution? simple and effective. open your gateway.php file from "My Release Build"

       

      Add this little line :

      $server->addDirectory(dirname(__FILE__) . '/services/');

      after this line :

      $server->setProduction($amf->production);

       

      reupload this file to your production, you should see your Flex, Zend, php & Mysql in action.

       

      Here is a sample link I have created :

       

      http://www.eiws.co.in/testzend.html

      you may also visit the endpoint file:

      http://eiws.co.in/gateway.php

       

      If anyone still faces this issue, can contact me at vaibhav.bhasin@yahoo.co.in.

       

      Credits: "To all developers who share their knowledge with everyone and google and thousands of blogs who provide a medium to share this knowledge"