Answer the question
In order to leave comments, you need to log in
Is it possible in PHP by means of the language itself or by means of some library to implement a subscription to some event from the outside?
The point is this. There is a form that the user fills out. After that, it should be redirected to the next form, but only after the third-party service, which received data from the first form through a webhook, returns us certain data that we will use in the second form. And you need to organize the receipt of the same data by the redirect script and only after that actually perform the redirect itself. The key point here is that the event occurs outside the thread of execution of the script that should control it.
More specifically, there is a php script #1 that the user is redirected to after filling out and submitting a form on one of the services like Google Forms. At the same time, the data through the webhook from the form service goes to Zapier, which sends data from the first form to one of the CRMs and then performs a webhook to php script #2, passing the transaction id and contact id received from CRM.
And as soon as our php-script #2 receives this data, it must transfer it in some way to php-script #1, and the latter will already substitute it in the redirect address and actually complete it. First of all, the most banal thought came up, to create a file in php script # 2, where to write the received values, and in php script # 1 to build a loop that checks for the next 20 seconds if a file with a certain name has been created, take data from it and delete it.
But the scheme, frankly, smells like crutches. As a result, I want to find some option when we subscribe to a certain event in php script # 1 and wait for it until it happens (of course, no longer than is limited by the settings for executing php scripts on the web server), and in php script # 2 we give birth to this event. How can this be implemented using php and some SDKs from certain products?
I think maybe look towards Redis, with its key-value scheme, but is it possible to organize something like a subscription to wait for the key to appear there? When it's enough, using their SDK in one way or another, write something like:
$redisDrv->when("found", $key, function () {
// do something;
})
Answer the question
In order to leave comments, you need to log in
look towards web sockets
as a matter of fact you open connection. send the data when it arrives -- the server will give it to the client
Why subscribe somewhere if everything in turn is normally called by hooks?
They are made for this.
And what chains you have there depends on what services and how you use it, if you need to transfer it to a bunch of other services, then you should do it, there's nothing wrong with that.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question