ChenXiu Posted September 2, 2021 Share Posted September 2, 2021 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 😃   Quote Link to comment https://forums.phpfreaks.com/topic/313653-way-to-poll-mysql-table-without-headache/ Share on other sites More sharing options...
Barand Posted September 2, 2021 Share Posted September 2, 2021 Step 3 - after the file_get_contents() is there a loop like this { read record insert record into db } while not end of file and are there 100's/1000's of records? Quote Link to comment https://forums.phpfreaks.com/topic/313653-way-to-poll-mysql-table-without-headache/#findComment-1589617 Share on other sites More sharing options...
kicken Posted September 3, 2021 Share Posted September 3, 2021 Create a script that checks the database for the content. If the content exists, display it in whatever manner you want. If the content doesn't exist, have the page refresh itself after 5 seconds. Quote Link to comment https://forums.phpfreaks.com/topic/313653-way-to-poll-mysql-table-without-headache/#findComment-1589619 Share on other sites More sharing options...
ChenXiu Posted September 3, 2021 Author Share Posted September 3, 2021 (edited) 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: have the page refresh itself 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 September 3, 2021 by ChenXiu Quote Link to comment https://forums.phpfreaks.com/topic/313653-way-to-poll-mysql-table-without-headache/#findComment-1589621 Share on other sites More sharing options...
kicken Posted September 3, 2021 Share Posted September 3, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/313653-way-to-poll-mysql-table-without-headache/#findComment-1589628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.