Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Is this code threadsafe? -- Director::urlParams()


Go to End


2 Posts   2753 Views

Avatar
julian

Community Member, 17 Posts

16 March 2007 at 2:15pm

Hi all, I'm a java guy by background and this worries me a little, unless I'm fundamentally misunderstanding the scope of statics in PHP?

Director.php: ‘Director::$urlParams = $arguments;’.

This is effectively a global variable. In java you’d die if you did this. Surely there’s only one instance of static (::) variables?

This is used by currentPage. Why is there a STATIC called currentPage?
This is then used in SiteTree::currentPage. I.e. a pretty significant function.

This is a concurrency issue. Stress testing should reveal request corruption as the first request is being filled with the second request's page info.

Anyone able to offer some insight? It's not hard to fix; you hang urlParams off $_REQUEST instead right? I'm (blindly) assuming $_REQUEST is thread-scoped.

This may well be showing my 'Java guy tries to do PHP' naivete.. any insight greatly appreciated.

Avatar
Sam

Administrator, 690 Posts

16 March 2007 at 2:29pm

PHP doesn't have threads. Each HTTP request is a different process, with its own set of globals. So it's not a problem.

Every time someone requests a page, main.php starts up, and runs through it threadlessly. Any shared data between requests needs to be put into the database or the session.

Good to see you're giving our code a good working over though. :-)