7 Replies Latest reply on Feb 23, 2010 4:05 PM by ccflyer

    Remote PHP Data Service Access

    ccflyer

      Hello Everyone,

       

      I've just begun to learn and experiment with Data Services in Flash Builder.  Currently, I am working on an AIR application which connects to a PHP Data Service to retrieve data from a MySQL database.  So far, I've been able to set up the PHP service, and correctly get data back from it, but have run into a problem.

       

      Since my application will be run in AIR, and my clients will not have a local server set up on their computers, I need to place my PHP service on a remote server somewhere, so the PHP files are still able to be interpreted and run.  I have looked around, but can't seem to figure out how to add a remote PHP service to a Flash Builder AIR project.

       

      Would anyone have any suggestions and/or comments?

       

      Thanks,

      Chris

        • 1. Re: Remote PHP Data Service Access
          Gaurav P(Adobe)

          You will need to copy all the services from your local server to the remote server, maintaining the exact directory and file names and directory structure.

          Also copy the created ZendFramework folder under the webroot. Remember to copy gateway.php and amf_config.php in the output folder as well.

          Once done, you will need to manually modify the generated service classes in the AIR project. modify the <ServiceName>.as files. Add a constructor and add the following line :

          _serviceControl.endpoint = "http://abs/xyz/gateway.php" // this is the location of the gateway.php you just copied on the remote server.

          • 2. Re: Remote PHP Data Service Access
            nikos101 Level 2

            yeah like he said, its a pain

            • 3. Re: Remote PHP Data Service Access
              ccflyer Level 1

              So, say for example I have a service which is made up of a single PHP file called dataService.php.  This file is located at the root of my current flex project.  I'm still slightly unsure of the exact steps needed.  I'll outline my understanding currently.  For this example, my remote server will be located at www.remote.com.  Please point out anything that I am misunderstanding or need to change.

               

              The steps I would take:

              1.  Copy 'dataService.php' to remote.com

              2.  Copy ZendFramework under webroot to remote.com

              3.  Copy gateway.php and amf_config.php to remote.com

               

              4.  Open dataService.as in Flash Builder and edit

                   _serviceControl.endpoint = "http://www.remote.com/gateway.php"

               

                   Note: Would #4 be editing dataService.as or _Super_dataService.as?

               

              5.  Export AIR project, which should now access the service over the internet.

               

              But what about current project settings in Flash Builder?  Do the web root and root url stay the same, or do they need to change as well?

               

              Thanks,

              Chris

              • 4. Re: Remote PHP Data Service Access
                Gaurav P(Adobe) Level 2

                - Since the file dataService.php was located at the root of your flex project, you must first create this folder on the remote server and copy the file there and not directly under the web root. Same applies to files gateway.php and amf_config.ini.

                 

                -The endpoint will be http://www.remote.com/<projectName>/gateway.php. Also update the dataService.as file(add the constructor) and not the _Super file. This is because the _Super file gets regenerated on any related resource change.

                 

                -For AIR projects you need not update rooturl and webroot on export. They do not have any effect at runtime for PHP services.

                • 5. Re: Remote PHP Data Service Access
                  ccflyer Level 1

                  Ok, I think I have done everything that you have told me so far, but still no luck.  Here are the exact steps that I took so far:

                   

                  1.  Copy DatabaseService.php (my service file) to http://www.remote.com

                  2.  Create my project folder on www.remote.com (i.e. /AAW_ManagementApp)

                  3.  Upload both gateway.php and amf_config.ini to www.remote.com/AAW_ManagementApp

                  4.  Add constructor to DatabaseService.as as follows:

                   

                  public class DatabaseService extends _Super_DatabaseService
                  {
                       public function DatabaseService()
                       {
                            _serviceControl.endpoint = "http://www.msuweb.com/AAW_ManagementApp/gateway.php"
                       }
                  }
                  
                  

                   

                  When I run my application, I get an error that pops up and that states:

                   

                  Send failed

                  Channel.Connect.Failed error

                  NetConnection.Call.BadVersion: : url:

                  'http://www.remote.com/AAW_ManagementApp/gateway.php'

                   

                  Any thoughts?

                   

                  Thanks,

                  Chris

                  • 6. Re: Remote PHP Data Service Access
                    Gaurav P(Adobe) Level 2

                    This error occurs when the connection was successfull but due to some error the AFM response could not be completely formed.

                    You can use netwrok monitor to see what is the response that you are getting. Reading the error can relveal the issue. If you cannot find the response or could not understand the error, revert back.

                    • 7. Re: Remote PHP Data Service Access
                      ccflyer Level 1

                      Thanks, I think I got it figured out.  It turned out to be that I didn't have my amf_config.ini file on the remote host configured correctly.

                       

                      - Chris