• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
not possible to call CI controllers simultaneously?

#1
[eluser]CI beyond[/eluser]
Hi folks,

In context of some 'live' notification i do an ajaxrequest on page load which in turn will call a function in a CI controller which loops indefinitely, spitting out some data every now and then.
Although this works perfectly with 'normal' php, it seems CI only allows one call at a time. As long as this infinite loop is active, i can't make any other calls to CI stuff. It simply hangs there till i manually kill off the loop.

I can hack around this using some 'normal' php together with CI stuff, but i rather do everything the CI way, so i can keep everything clean.

Is this a known issue or maybe even a config setting? Also, if anyone knows of a better way of doing instant notification about changes on the server i'd be glad to hear it Smile

Thanks in advance!

#2
[eluser]Crafter[/eluser]
I don't think its true that CI will disallow simultaneous calls. (Theoretically) Each call is made as a seperate call to your web server, who then hands this off to your CI application. The web requests work in a connection-less environment - that it - the webserver connects, sends the data, then disconnects from the browser.

I'd like to ask why you are doing an infinite loop. It is perhaps not your browser that is spending CPU time in the loop. The Prototype ajax library has a way of periodically sending Ajax requests without sitting in a tight loop. Not sure which Javascript library you are using.

#3
[eluser]CI beyond[/eluser]
Hi crafter,

thanks for your response. I don't use any js library.
Of course i could accomplish the same by polling, but it's not as efficient as only returning data when there's actually something to return Smile

It does work when i call .php files directly instead of via de <url>/index.php/my_class approach. so it seemed logical to me CI has something to do with it.

I agree with you that it _should_ work, because each request is dealed with separately. The infinite loop is because i'll keep looking for changes while the page is active. On unload i stop the loop and everything ends.

#4
[eluser]Crafter[/eluser]
just guessing here, but you should be using a setTimeout call in your code. I'd use that instead of SetIntervak, hust to give your app some breathing space.

Have you tried turining on logging on your server and seeing if the requests are coming through fast enough?

#5
[eluser]CI beyond[/eluser]
i'm pretty sure the problem is not on the clientside, i don't loop on the client in any way. I only do the xmlhttp call and wait for changes in it's readyState.

apaches access_log only shows the requests after they are complete ( i loop for a limited time in this testingscenario) so they're not very helpfull for seeing if calls arrive on the server simultaneously. I monitor netactivity using firebug and requests are made to the server.

Together with the fact it does work when calling a normal .php file i'm quite sure it's something related to CI. I'll do some additional testing to see if it's anything i've done wrong on my end.

#6
[eluser]CI beyond[/eluser]
hmmz, i think i just found it. When using CI i call session_start() from a controllerclass. session_start() will just block till the other request (the loop) has been terminated. I'm not quite sure yet why it's doing that, maybe you have an idea?

#7
[eluser]CI beyond[/eluser]
It seems session_start() acquires an exclusive (write)lock on the sessionfile, causing another session_start() to wait till it gets released. In my case calling session_write_close() as soon as the loop is initialized solved my problems.

thanks for your efforts Crafter Smile

#8
[eluser]Jim OHalloran[/eluser]
Instead pof PHP's native session handling you might want to try CI's in-built session library. It doesn't use the PHP session functionality, and may not suffer from this problem.

This post on the "Thwarted Efforts" blog deals with PHP Sessions and race conditions, and seems to describe a problem similar to what you're experiencing. It provides a solution that allows you to lock only a single value in the session which might be of benefit to your situation.

#9
[eluser]CI beyond[/eluser]
Hi Jim,

thnx for your suggestion, but i've tried CI's built-in sessionlibrary a couple of months ago and it didn't quite suit my needs. I don't remember any specifics though.

As for the article, looks like an interesting read Smile Something for tomorrow during breakfast Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.