Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » Is this code threadsafe? -- Director::urlParams()

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

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

Page: 1
Go to End
Author Topic: 2106 Views
  • julian
    Community Member
    17 Posts

    Is this code threadsafe? -- Director::urlParams() Link to this post

    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.

  • Sam
    679 Posts

    Re: Is this code threadsafe? -- Director::urlParams() Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.