Search code examples
phpcrondata-sharing

Share data between cron-job and webserver executed PHP scripts


The one below is a common way how a master and a child script do data sharing:

cron job -- schedule --> master script

HTTP request -- trigger --> child script

master script --> [database] <-- child script

But is it possible to them to share the data using any of these below, instead of the database?

  • global variable
  • system storage
  • session storage
  • memcache / apc / any other thing like these

Solution

    1. global variable - no
    2. system storage (from comments: this is command line) - no because that would involve one launching the other, and still be one-way...
    3. session storage - yes, using named session, but this will resort to files by default (can be configured to use shm and then in-memory...)
    4. memcached - yes
    5. apc - yes, but will require explicit configuration to enable in cli sapi
    6. files - yes. And to speed things up, you can use ramfs to store files in an in-memory filesystem.
    7. sockets - yes (make one of the a listener and connect from another)
    8. database - yes (why not, actually?)

    In case i left anything out, you can search for php interprocess communication