Python Forum
how to run a python script in the background on my wordpress website
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to run a python script in the background on my wordpress website
#1
Hi all
I have a python script I would that I would like to have running all the time in the background that looks at values in the wordpress website's database tables and does certain actions based on the values in the database tables. How do I run the python script in a TSR terminate stay resident manner or as a service if you will in the background of the WP website?
Reply
#2
Why does this need to run in the same place as the website? Why does it need to be coupled to the database? That coupling is a really bad idea because it makes the database hard to change later if you needed. Also, is this thing going to poll for changes so that it can do something if the values change? If so, would an event-based system make more sense?
Reply
#3
(Aug-13-2021, 05:33 AM)ndc85430 Wrote: Why does this need to run in the same place as the website? Why does it need to be coupled to the database? That coupling is a really bad idea because it makes the database hard to change later if you needed. Also, is this thing going to poll for changes so that it can do something if the values change? If so, would an event-based system make more sense?


The python script is running once an hour to look for changed or new entries in the database that the wordpress site is updating based on user inputs from forms.

How would one accomplish this ?
Reply
#4
You haven't said anything about the infrastructure, but if you're running this program on a VM or your own machine, then you can use the operating system's scheduling system (e.g. cron on UNIX). Cloud computing services may have a way to schedule things to be run (I think Heroku does from memory, but have never used it).

Again, I caution you about coupling to the database - you'd likely be better off exposing an API to serve the data and have your app use that. Of course the API is then coupled to the database, so I suppose it depends where you want that coupling. I don't know if WordPress already exposes data via an API.

If you wanted to do event-based instead of polling, then there are options like

- putting a message on a queue that your app consumes
- running your app as a serverless function (e.g. AWS Lambda, Azure Functions, etc.) that's triggered by the update.

Depends on cost, complexity for you/others to build and maintain, what constraints you have, etc.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python, Salesforce and WordPress arthurk88 1 726 Nov-21-2023, 10:13 AM
Last Post: Larz60+
  Retrieve website content using Python? Vadanane 1 1,276 Jan-16-2023, 09:55 AM
Last Post: Axel_Erfurt
  Python API for Wordpress Simlock 4 3,739 May-23-2022, 06:47 PM
Last Post: LaverneDejardin
  I want to create an automated website in python mkdhrub1 2 2,432 Dec-27-2021, 11:27 PM
Last Post: Larz60+
  Python to build website Methew324 1 2,243 Dec-15-2020, 05:57 AM
Last Post: buran
  Scraping all website text using Python MKMKMKMK 1 2,093 Nov-26-2020, 10:35 PM
Last Post: Larz60+
  Article Extraction - Wordpress svzekio 7 5,309 Jul-10-2020, 10:18 PM
Last Post: steve_shambles
  If I use a php script, like WordPress and Elgg, can I program an plugin by Python? Abdulaziz 0 1,626 Jun-23-2020, 06:54 PM
Last Post: Abdulaziz
  Python Webscraping with a Login Website warriordazza 0 2,610 Jun-07-2020, 07:04 AM
Last Post: warriordazza
  Python tool based on website? zarize 2 2,496 Mar-21-2020, 02:25 PM
Last Post: zarize

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020