Welcome to WebmasterWorld Guest from 54.146.201.80

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

A riddle

     
8:10 pm on May 6, 2011 (gmt 0)

Moderator from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4059
votes: 0


I am an event. I only happen if you don't attend. If you show up, I'm canceled. Sometimes cookies are served. I produce no output, everything that happens in me is hidden, and httpwebwitch needs to debug me today. Who am I?
10:42 am on May 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Feb 22, 2009
posts:1396
votes: 0


Sounds like a virus!

What is it that you're trying to see? A process? Server side/Client side? I guess as this is something that is only present IF you have actioned by pressing a button, or mousing over something.. Other than that - no idea - though very intrigued. Good luck on this endeavour...

Cheers,
MRb
4:13 pm on May 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member trillianjedi is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 15, 2003
posts:7242
votes: 0


Sounds like some form of HTTP timeout.
5:11 pm on May 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 27, 2001
posts:1472
votes: 0


cron?
5:26 pm on May 7, 2011 (gmt 0)

Senior Member from FR 

WebmasterWorld Senior Member leosghost is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Feb 15, 2004
posts:6717
votes: 230


else ?
3:08 pm on May 8, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts: 4388
votes: 2


Cron was my guess too
1:44 pm on May 9, 2011 (gmt 0)

Moderator from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4059
votes: 0


ahh, no sorry you're all wrong. on Friday I was debugging the garbage collection routine that prompts the expiry of a session.

>> I only happen if you don't attend. If you show up, I'm canceled.

if you refresh a page that's uses the session, the session doesn't expire. Looking at the contents of $_SESSION changes the session. It's rather schroedingeresque.

>> Sometimes cookies are served.

PHP's default session behaviour is to send a cookie header in the response

>> I produce no output, everything that happens in me is hidden

It's not the result of a normal request/response process prompted by a browser, so there's no convenient output, thus nothing that you can echo out to a browser to see if the process worked.

In this situation, most of your debugging methods won't work. Tricky stuff, because it happens only if the expiry lapses, and any hit to the session will extend it. To expire the session, you need to knock back the expiry on it (or else you're stuck waiting until it expires), then hit the server to trigger GC, but Not in a way that accesses your session (because that will extend the expiry again)

Overriding the default session behaviour is a finicky business, but there are situations when you need to get your hands dirty in it. For instance, when developing a server-side API that requires authentication, you'll likely want to store your sessions in a mysql database, not in /tmp files. This gives your app immediate access to the sessions, so your app can establish authentication for requests. It's also useful to override the session handler if your app accepts the session token as something other than a cookie, which is quite common if you're designing an app for something other than a web browser.

It's done using session_set_save_handler() [php.net]

So how do you debug a process that has no output, and happens outside the context of a browser-origin request?

one easy way: liberal use of error_log() [us.php.net]

error_log() sends a string into the error log. And viewing the real-time contents of your error log is quite simple. Go into an SSH terminal and navigate to your error log - it's often in /var/log/httpd/ - and do this command:

tail -f error_log

the "tail -f" is a great trick to know. It flows the data from error_log - any new appended lines - straight onto the screen. When that's running, you can trigger your session expiry (if you know how) and you'll see the output of error_log() appear in the terminal window.

If you don't want to use error_log, you can output to a file using file_put_contents() [php.net], with "FILE_APPEND" as the third argument. That accomplishes the same thing.

So why'd anyone need to hook into the garbage collection routine?

In my case there are connections to other servers that are established when a session is created, that needed to be forcibly closed when a session expires. So, in the "destroy" and "gc" parts of the session handler, I needed the handler to do a little extra work. This can only be done if you've overridden the default session handler with your own.

It's powerful stuff.
2:14 pm on May 9, 2011 (gmt 0)

Senior Member from FR 

WebmasterWorld Senior Member leosghost is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Feb 15, 2004
posts:6717
votes: 230


+1 for
schroedingeresque.

;-)
3:17 pm on May 9, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts: 4388
votes: 2


Well done!
On the same topic how to purge your Apache error log:
<<<<
-bash-3.2# hostname
whatever.com
-bash-3.2# pwd
/etc/httpd/logs # mostly resides in there
-bash-3.2# > error_log <----- Use to empty log
-bash-3.2#
>>>>
3:43 pm on May 10, 2011 (gmt 0)

Moderator from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4059
votes: 0


that's nifty henry0, I usually do this:

#> echo "" > error_log

which is basically taking an empty string and writing that as the content of error_log.

your way is more succinct
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members