Using the PHP SDK in Business Logic possible?

The exception you receive can be thrown only if BL works too long. Try the following:

  1. Make the handler as easy as it can be: leave there only “echo “inside after handler\n”;”
  2. Run ./CodeRunner.sh
  3. Call POST method for this table from REST console
  4. If it works fine ( object is created and you see phrase in coderunner logs ) - add one more row into handler: "echo “objectId: " . $blProjectObject->getObjectId() . “\n”;”
  5. Stop coderunner with ./StopCodeRunner.sh and repeat steps 2 and 3
  6. If it’s still OK ( you see objectId in logs ) - add the following row: "echo “ownerId: " . $blProjectObject->getOwnerId() . “\n”;”
  7. Stop and start coderunner again
  8. Login as any user through REST console and repeat step 3
  9. Check coderunner logs
    Please notify me about results, I hope that this way we shall find out what’s causing the problem.
    best regards,
    Alex

Hi Alex,

See my previous comment, when executing coderunner.sh without secret it causes the error I got.

Hi, Barry!

Ok, it’s nice that you’ve got your code working.
best regards,
Alex

Yes, it’s great to have it running now!

One more question: Im now modifying my code, but after saving and restarting coderunner it still outputs the old code?

Any idea?

Open file “config.php” and check value for ‘‘location_classes’’. It should point correct folder with your code.

The best way to by-pass this problem is to generate new BL project from console and replace /classes folder in generated code with /classes folder with your old code.

I checked my config.php, it contains the correct path.

I also manually checked the eventhandler php file, which contains the correct code.

I removed the debug event from the console, which got recreated when running coderunner again.
However, still the old code executes?

There is no magic here, if the old code executes, you have a PHP interpreter that has old code cached somewhere. You could go for something drastic like scanning your harddrive to find where the old files are…

I’ve manually checked with vi that the php file is correct. It is. However i’m still getting the old output from coderunner.

I even edited coderunner.sh to not execute php but /usr/local/php5/bin/php (im on a mac, bypassing the default php).

But no glory -> still the old code get’s executed.

Im confused now.

Ok, after rebooting my mac, running coderunner again (with secret key):

Try uploading blProjectObject: <ProProject.BLProjectObject: 0x7feb5b487030> with owner: Optional(“xxxx@xxxx.xxl”)
Fault! Error Creating BLProjectObject ‘test’: FAULT = ‘15000’ [Custom business logic execution has been terminated because it did not complete in permitted time - 20 seconds] <Custom business logic execution has been terminated because it did not complete in permitted time - 20 seconds>

and zero output in the coderunner debugger, just ‘waiting for events’

Where does the “Try uploading blProjectObject:” message come from?

Thats logging I added in my iOS code.

<Snap-Snap form an earlier post in this thread>

The object is created using the iOS API. The owner is set, see this debug output from my iOS app:

print (“Try uploading blProjectObject: (blProjectObject) with owner: (blProjectObject.owner?.email)”)

output:

Try uploading blProjectObject: <ProProject.BLProjectObject: 0x7f9055c86e50> with owner: Optional(“xxxx@xxxxx.xxx”)

Now getting the message:

Fault! Error Creating BLProjectObject ‘test’: FAULT = ‘15000’ [Custom business logic execution has been terminated because it did not complete in permitted time - 20 seconds] <Custom business logic execution has been terminated because it did not complete in permitted time - 20 seconds>
</Snip Snap>

To make it more clear, here is the full method:

private func createBLProjectObject(projectObject:CDProjectObject) {




        syncIsRunning = true
        
        // First convert the projectObject
        let blProjectObject = blParser.convertProjectObject(projectObject)
        
        print ("Try uploading blProjectObject: \(blProjectObject) with owner: \(blProjectObject.owner?.email)")
        
        // Upload the object
        let dataStore = BackendlessManager.sharedInstance.backendless.persistenceService.of(BLProjectObject().ofClass())
        
        dataStore.save(blProjectObject, response: {(response:AnyObject!) -> Void in
            print ("ProjectObject Upload OK: ",response.objectId)
            
            // Update the backendID to the objectId of the Backendless Entity
            self.updateBackendID(projectObject: projectObject, blProjectObject: response as! BLProjectObject)
            
            // Save Core Data
            self.cdHelper.save()
            
            // Upload any customproperties that contain NSData
            self.dataToUpload(projectObject)
            
            }, error: {(fault:Fault!) -> Void in
                print ("Fault! Error Creating BLProjectObject '\(projectObject.name)': ",fault)
                if fault.faultCode == "1000" {
                    // ID Not found, remove it so object get created again
                    print ("stored backendID was not found in Backendless (objectId), remove it so the object get's recreated")
                    projectObject.backendID = nil
                    self.cdHelper.save()
                }
                self.uploadFailed()
        })
    }

The error you are getting indicates that the server-side code takes more than 20 seconds to run. The client-side code is pretty irrelevant for the error.

I posted the code because you asked where does the “Try uploading blProjectObject:” message come from? I thought it would be better to post the complete method so you can see what is going on.

Anyway: The server side code does as good as nothing, I just changed the log message a bit (see first post for the code) and commented out the group creation.

Now the weekend is gone and Im back at the office, I tried coderunner again: This time the timeout error is gone and it just works.

Is there any explanation for this behavior?

Im going to change the code a bit and rerun again to see what happens.

Ok, I just modified my code and restarted coderunner: Guess what: Problem gone -> Code change is reflected directly.

Did anything change this weekend on your end?

Hi, Barry!

No, there were no modifications.
Anyway, we shall keep on trying to reproduce this issue. Notify us please if you have an idea or this issue reproduces again.
best regards,
Alex

And I have got the same problem again:

Try uploading blProjectObject: <ProProject.BLProjectObject: 0x7fa7b2d13000> with owner: Optional(“xxxxx”)
Fault! Error Creating BLProjectObject ‘Afghaanse’: FAULT = ‘15000’ [Custom business logic execution has been terminated because it did not complete in permitted time - 20 seconds] <Custom business logic execution has been terminated because it did not complete in permitted time - 20 seconds>

I have no clue what the trigger is, but once I get this timeout, there is nothing I can do but wait for hours, or even days before all starts working again.

I now even commented out all code inside

public function afterCreate( $runner_context, $blProjectObject, $execution_result ) {

But it doesn’t help, still keep getting the timeout error.

Ok, it look like when not using the ‘reset connection’ function in the debug page of the custom logic, but instead killing manually the process is causing this problem.

So it now looks like it is working ok if I run coderunner -> create object -> check test results in debugger -> press ‘reset connection’ -> modify server code -> re-run coderunner.

If for some reason this doesn’t solve my problem then I’ll report back,

Barry, do you use “kill” for stopping coderunner?

yes, killall -9 php