php - How to talk between HTTP request & cli class objects -


i have application running that's listing http request. each request passed single page framework object $app instantiated , takes care of routing / controller / model etc.

now have class object instantiated via. cli script lets call $cliapp problem how make both object talk each other. $app instantiate every-time there new request.

but $cliapp instantiate once when script ran. scripts runs in loop via $loop object php react event loop.

cli app running websockets. want http & sockets communicate via. http api.

p.s. :

right have 1 solution use message queueing e.g. 0mq etc. seems overkill since i'm not looking scale , keep simple.

another solution i'm trying , feels right share sptstorageobject between threads created $http request , thread created $cli request. maybe question of dependency injection , i'm having troubles share $store object.

if understand correctly, have (assumptions noted):

  • a normal php web app communicates on http (presumably on apache or similar webserver)
  • a long-running php cli app communicates on websockets.

presumably both apps receiving communication web clients on ongoing basis. presumably have own persistent data stores, such mysql database or similar, perhaps sharing same one.

i'm going assume need goes beyond each application accessing up-to-date data persistent data store (or 2 processes use separate data stores), , need on-demand communication between 2 processes.

you're on right path message queues, note it's needless complexity add third dedicated inter-process communication layer when you've got 2 communication layers work fine on own.

what need cli app speak http when needs initiate communication web app, , web app speak web sockets when needs initiate communication cli app.

what looks in practice simple.

in cli app, use curl initiate http connection web app. simple, there endless resources out on web along way , if stuck coming here new question specific problem going. requires in web app following:

  • appropriate endpoint(s) cli app can send requests to, if basic client facing pages won't suffice
  • some method authenticate cli app if needs access data should not available web clients

for web app initiate websocket connection cli app, it's bit more complicated because i'm not aware of native php functionionality targets websocket protocol. however, did find this (extremely permissive) github project purports give ability set web socket server, , also includes client script use connect , send/receive data while web app process lives, , shut down when you're done. appears still have minimal activity, use directly or use starting point write own websocket client.

in case, in reverse situation, need cli client recognize , authenticate traffic web client can serve appropriate data it.

if reason scenario won't work you, you're message queues or shared data stores (someone suggested redis, can act hybrid data store/message queue under circumstances).


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -