Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4621110
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:39:13+00:00 2026-05-22T02:39:13+00:00

At work we ran up against the problem of setting server-side cookies – a

  • 0

At work we ran up against the problem of setting server-side cookies – a lot of them. Right now we have a PHP script, the sole purpose of which is to set a cookie on the client for our domain. This happens a lot more than ‘normal’ requests to the server (which is running an app), so we’ve discussed moving it to its own server. This would be an Apache server, probably dedicated, with one PHP script 3 lines long, just running over and over again.

Surely there must be a faster, better way of doing this, rather than starting up the whole PHP environment. Basically, I need something super simple that can sit around all day/night doing the following:

  1. Check if a certain cookie is set, and
  2. If that cookie is not set, fill it with a random hash (right now it’s a simple md5(microtime))

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:39:14+00:00Added an answer on May 22, 2026 at 2:39 am

    You could create a simple http server yourself to accept requests and return the set-cookie header and empty body. This would allow you to move the cookie generation overhead to wherever you see fit.

    I echo the sentiments above though; Unless cookie generation is significantly expensive, I don’t think you will gain much by moving from your current setup.

    By way of an example, here is an extremely simple server written with Tornado that simply sets a cookie on GET or HEAD requests to ‘/’. It includes an async example listening for ‘/async’ which may be of use depending on what you are doing to get your cookie value.

    import time
    import tornado.ioloop
    import tornado.web
    
    
    class CookieHandler(tornado.web.RequestHandler):
        def get(self):
            cookie_value = str( time.time() )
            self.set_cookie('a_nice_cookie', cookie_value, expires_days=10)
            # self.set_secure_cookie('a_double_choc_cookie', cookie_value)
            self.finish()
    
        def head(self):
            return self.get()
    
    
    class AsyncCookieHandler(tornado.web.RequestHandler):
        @tornado.web.asynchronous
        def get(self):
            self._calculate_cookie_value(self._on_create_cookie)
    
        @tornado.web.asynchronous
        def head(self):
            self._calculate_cookie_value(self._on_create_cookie)
    
        def _on_create_cookie(self, cookie_value):
            self.set_cookie('double_choc_cookie', cookie_value, expires_days=10)
            self.finish()
    
        def _calculate_cookie_value(self, callback):
            ## meaningless async example... just wastes 2 seconds
            def _fake_expensive_op():
                val = str(time.time())
                callback(val)
            tornado.ioloop.IOLoop.instance().add_timeout(time.time()+2, _fake_expensive_op)
    
    
    
    application = tornado.web.Application([
        (r"/", CookieHandler),
        (r"/async", AsyncCookieHandler),
    ])
    
    
    if __name__ == "__main__":
        application.listen(8888)
        tornado.ioloop.IOLoop.instance().start()
    

    Launch this process with Supervisord and you’ll have a simple, fast, low-overhead server that sets cookies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This originally was a problem I ran into at work, but is now something
I have a process that has to be ran against certain things and it
I have ran into a situation at work where it has been proposed to
ive ran into an issue while creating a PHP telnet script at work to
I ran today against a quite subtle issue I'd like to have your opinion
I've ran into the following questions at work, and I don't have the experience
At work, we have multiple branches that we may be working on at any
I work a lot with network and serial communications software, so it is often
I recently ran into a problem caused by using fstream::eof(). I read the following
I have a strange problem with absolute positioning and sizing elements to fit around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.