getting response string/object from php classes
14 posts
• Page 2 of 2 • 1, 2
Re: getting response string/object from php classes
I see 'hi' and 'hiStr' are both null?
They were till I added $hi to the global variables. After that both properties $hi and phpObj.hi showed up with the correct strings as their values. However I still receive the same error message as above.
I can show my code but really most of the functionality Im testing is only using the sample (hence all the hi() functions). The main difference however is the
- Code: Select all
Using
As you pointed out earlier, these statement do work if placed with the same using block as the declaration of phpObj. But outside of the statement it does not.
- owengerig
- Posts: 10
- Joined: October 16th, 2012, 2:50 pm
Re: getting response string/object from php classes
'using' is C# construct that ensures, the object is Disposed at the end of block.
It is recommended to dispose 'RequestContext' because it simulates PHP lifecycle - at the end, PHP objects with __destruct method are finalized. It also cleans some resources. As stated before, all the PHP operations should be performed inside the RequestContext.
Anyway using phpObj outside RequestContext should not cause Null reference exception.
It is recommended to dispose 'RequestContext' because it simulates PHP lifecycle - at the end, PHP objects with __destruct method are finalized. It also cleans some resources. As stated before, all the PHP operations should be performed inside the RequestContext.
Anyway using phpObj outside RequestContext should not cause Null reference exception.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: getting response string/object from php classes
I noticed the output variable was null as well and figured I would try adding another using statement to the Page_Load function (on Post Backs) and now it works. Kinda of have a feeling this isnt the right way however
I understand what your saying about simulating the php life cycle but I need these objects to stay initialized for the session.
- Code: Select all
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
this.phpObj = (dynamic)HttpContext.Current.Session["phpObj"];
using (var request_context = RequestContext.Initialize(ApplicationContext.Default, HttpContext.Current))
{
//part 1
//Gets PHP output stream
output = ScriptContext.CurrentContext.Output;
//Gets GlobalScope object
global = ScriptContext.CurrentContext.Globals;
}
}
else
{
using (var request_context = RequestContext.Initialize(ApplicationContext.Default, HttpContext.Current))
{
context = request_context.ScriptContext;
context.Include("Client.php", false);
context.Include("Crypt.php", false);
context.Include("Exception.php", false);
//part 1
//Gets PHP output stream
output = ScriptContext.CurrentContext.Output;
//Gets GlobalScope object
global = ScriptContext.CurrentContext.Globals;
phpObj = global.@class.Fuze_Client("https://partnerdev.fuzemeeting.com/", "83666136", "Q5iI4bcoADj9QGrMC6Ss5V34VK1FxKNZ");
//phpObj.hi();
//output.WriteLine("hi: {0}<br/>", phpObj.hi);
//output.WriteLine("{0}<br/>", phpObj.hi());
}
HttpContext.Current.Session["phpObj"] = this.phpObj;
}
}
I understand what your saying about simulating the php life cycle but I need these objects to stay initialized for the session.
- owengerig
- Posts: 10
- Joined: October 16th, 2012, 2:50 pm
Re: getting response string/object from php classes
The phpObj can stay in session, RequestContext is needed internally for web-oriented functionality in Phalanger, by initializing it at the beginning of request and Disposing it at the end, you will increase performance mostly, and allow Phalanger to cleanup resources etc and objects with __destruct.
You can do it in global.asax:
- at Application_BeginRequest: RequestContext.Initialize( ..., HttpContext.Current )
- at Application_EndRequest: RequestContext.CurrentContext.Dispose();
To get ScriptContext anywhere in the code:
- ScriptContext.Current
Thanks
You can do it in global.asax:
- at Application_BeginRequest: RequestContext.Initialize( ..., HttpContext.Current )
- at Application_EndRequest: RequestContext.CurrentContext.Dispose();
To get ScriptContext anywhere in the code:
- ScriptContext.Current
Thanks
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
14 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 10 guests