Home > other >  How to make query system with PHP and MySQL?
How to make query system with PHP and MySQL?

Time:02-10

I have some script on my website, when logged user can put some data into form, and then, PHP script will do an exec() function for some time, but webpage is hold still, until that PHP script and exec() command will end. If user close the page - he is resolve nothing, and he need to run script again. I want to know, if that possible, to do query mode, with existens database with users. What i want:

  1. User put some data and execute script. It will put record to database with id=1 status=running
  2. User can close webpage and script still running
  3. Between that, another user want to put some data too, but webpage checks currently executing scripts from database, and say "I'll do it later, your queue is 1", and add an record in database id=2 status=queue
  4. First script ends executing, return values to database and set up id=1 status=done
  5. Then if in database exist some queue records, it will execute it too.
  6. Users can open back website, and get data from it.

What problem that i have now. PHP function exec() can somehow crash, or return different data, so i need to catch it right, when it executes in background. I don't know, how to correctly do, what i want. Some of the solution is, to create a daemon on PHP, but it can be difficult to control/manage daemon, i suppose.

What is the correct way to use, without any of libraries, from scratch? It can be some examples of this? If the daemon is the correct solution - how can i setup it and control?

CodePudding user response:

What you defines resemble the often used CRON/Background Process/AT(on Windows). i.e.

  1. Create a PHP Form which save to DB as you want.
  2. Then create a new PHP Script, that read from DB. perform action, store data in dB.
  3. This new script is configure to run every minute/5 minute/30 minute or once per day in cron service of your server. that run PHP Script on command line.
  4. It perform operation and you can send email and db update as required.

For Exec crashing it is hard to tell the reason, there are literally 1000s of them and each has there own scope of resolution. So please post that individual as separate question with more detail. Look for your hosting environment cron and hwo to write cron scripts.

  •  Tags:  
  • Related