PHP Execute Code AFTER user receives a response - php

I have a api built with PHP & Codeigniter + RestClient and its getting to the point speed matters. We have ALOT of code that the user should really not need to have to wait on to receive a response from the API that I would prefer to be executed AFTER the user receives a api response. Is this possible and if so how?

This is possible if your server run PHP as PHP-FPM. See in documentation functions with prefix fastcgi_
You can move your "special" code to separate file and run this file as daemon. Not sure about PHP scripts, but for Python scripts this is possible.

Related

Connecting to SimPro API via Web

This is a very similar to the question posed at Use php and simPro API to list customers.
The response to that question suggests downloading examples from GitHub. I have downloaded the SimPro examples at GitHub and have them functioning on the commandline.
I want to be able to use a web page as an intermediary between my FileMaker Pro database and the SimPro API. I can pass data to a web page written in PHP. It can convert the data to JSON and form a call to SimPro receive a response and display the success or failure as a web page.
Presently I have my JSON data hardcoded so that I can test the process. When run from a web browser I don't get a result, though the code works perfectly well running from the command line.
I'm not sure what I need to do make the examples web compatible. Can someone push me in the right direction?
Would be more than happy to help - could you post a snippet of your code - minus the auth info of course - so that I can try to assist?
Do you have your code printing anything else to the browser first - so that you make sure the script is actually executing as it should from the web server side - and have you checked your web server logs for any errors?
In some cases I've seen this is usually due to PHP config (there are separate configs for CLI and CGI in most setups) and can mean whilst libraries are loaded in one environment they may not be available to the other. The web server also usually requires a reload if you have just loaded libraries for use within your script.
Hope that helps.

How to call PHP from MATLAB?

I have some analysed data in MATLAB which I need to send to a server. I have a php link to access the server. Any idea how to call php from MATLAB?
Thanks.
If you will frequently send data back and forth between MATLAB and your web server, perhaps you can consider using SaturnAPI. SaturnAPI provides a REST interface for your Matlab and Octave scripts, so that you don't have to install anything on your own server. It can even send Base64 encoded 3D plots to you. Here is the demo. Below is a diagram showing that you can pass inputs to the script via the SaturnParams variable in the HTTP call.
Disclosure: I work on SaturnAPI

How to have a listener PhP script respond to GET requests

I'm trying to accomplish remote php call and return as described in this question: PHP: Remote Function Call and returning the result?
However, I don't know how to make the listener script that responds to the GET request. How do I create the script, allow it to be called remotely, and have it process the request appropriately? Is there an example somewhere?
I understand this is probably a very low-level question, but I'm very new to PhP.
You don't need to implement a listener, the web server is doing that for you. Just create a script and put it in your web directory. When the web server receives a GET request to that script, it will execute the PHP script.
In the script, you can just echo the values that you want to send back in a format that your calling function understands. (Of course you could also set some headers, if you feel that this is necessary).
Your listener PHP script responding to a remote call should be just like a script responding to a web browser's request. Use $_GET to get the input data.

PHP client communicate with C++ Server over TCP

Im trying to get a Php page to be able to communicate with a C++ server. It must be able to recive and send at all time (and the same time). When the php page recives a string it shall make some changes in Mysql db but at the same time send other strings to the server.
You can think of it as a chat, but then the php recive a string it shall be formated.
The C++ server is up and running only the php client side is a mystery for me.
Is there any example code that anyone can help me with?
Thx!
Well first of all you need to understand and remember that PHP in itself is stateless. You can have PHP receive a request and parse it and do something with the gained information, but after that the request closes.
One solution you could try is having your C++ app HTTP POST to a PHP script. This script can parse and analyze the request and take action upon it.
Store something in the database
Create a response
Output the response
The C++ app can then do something with the response.
This will work but if your actual use case is a chatroom or something of the likes there are better solutions than using PHP.

Run php script remotely

I have a php script (qa.php) that my app points to on my current server. I just recently switched servers and want the qa.php script running from this new server.
Is there a way to have a php script redirect or automatically run the remote php script?
If you mean a redirect in the sense of a client visiting this page, you can use the header() function to change the location header and simply perform the redirect.
header('Location:http://www.your-new-domain.com/qa.php');
But if you mean (and this I'm assuming) running the script without direct client interaction, there are a few different approaches. One good way is to use the Curl library to send a request formed the way you'd like to the script. I've used this method in scheduling cronjobs before that had to fire signals to several controllers at once and record the output.
http://www.php.net/manual/en/intro.curl.php
It's also acceptable to use the file_get_contents() php function to simulate a client visit on the page if you don't need to manipulate any specific headers for the request going to the server-side script.

Categories