Jump to content

Way to poll mySQL table without headache


ChenXiu

Recommended Posts

1.) My query script requests data from 3rd party.
2.) The 3rd party processes request, and about a minute or so later, pushes results to my server.
3.) My PHP code uses file_get_contents("php://input") to capture and insert that data into my mySQL table.
4.) I sit at my computer, waiting up to 2 minutes, constantly refreshing my browser's mySQL page to see if mySQL has results yet.

To avoid having to sit at my computer refreshing my page like a monkey pressing the "give me a banana" button, I have a question.

Question:
Without having to learn an install one of today's complex Python/Java/Javascript technologies, is there a simple way to have my browser simply display that data when it's ready?

With my limited knowledge, I'm experimenting with SSE, but it looks like SSE polls actual files, for data that's been written. Somehow there might be a way using ajax to have a 2nd page with an infinite loop where mySQL is queried every 5 seconds, and when $db->query is "TRUE" then it will a.) writes the data to a file using file_put_contents and b.) break out of the mySQL loop. And when the file gets written using file_put_contents, SSE will be polling that file and delivering the results.

Am I going about this wrong? Currently I am at the "thinking up an idea how to do this" stage. And before I spend 6 weeks trying to write the code, I thought I'd check to see if there isn't already a "one-liner" that accomplishes all of this 😃
 

 

Link to comment
Share on other sites

13 hours ago, Barand said:

Step 3 - after the file_get_contents()

There is no loop, I just have three lines of code that do this:
file_get_contents("php://input") ---> Sanitize ---> then insert into mySQL database ---> exit.
My computer browser has an html/mysql page that queries the database for the results I'm waiting for. I refresh the browser while patiently waiting.
There are 100s of records -- whenever I query 3rd party server and they post results to my endpoint, my mySQL database increases in size.

10 hours ago, kicken said:

At first, that's what I had done, but this browser page is the same one I use to query the 3rd party for new data. If this browser page is auto refreshing to display the results previous request, I can't be using this browser page to be posting my next request.

The more I think about this, the more the logic of it all fades away...
1.) There are 100's of records that are slowly building to the 1000's of records. I only want my most recent request showing up.
2.) How can I continue using the page to post data to query the 3rd party if all of sudden my previous request results commandeers the page...

My computer monitor is only so big.... I already have 4 windows open to do what I need to do. It sounds like I'm going to need a 5th browser window open that will say "ChenXiu, Your Results Are Ready."

I wish I could think out of the box on this one... I'm sure there is an elegant way of accomplishing this.

Edited by ChenXiu
Link to comment
Share on other sites

6 hours ago, ChenXiu said:

If this browser page is auto refreshing to display the results previous request, I can't be using this browser page to be posting my next request.

Sounds like you need to either split the functions into different pages or learn enough Javascript to do background requests and update the current page.  The Javascript you need wouldn't be that hard probably.  Either load up jQuery and use it's ajax functions or learn how to use fetch() and update the page with the DOM.

 

7 hours ago, ChenXiu said:

I'm sure there is an elegant way of accomplishing this

There probably is, but as of yet we don't really have enough info about the overall process to be of much help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.