1

I am working on flight portal.

If any user book a ticket he/she will get some status like BOOKING SUCCESS / BOOKING PENDING.

If the status is BOOKING SUCCESS the user will get a mail with the ticket details.

In case of BOOKING PENDING a message ( your ticket is in process, you receive a message/email after the ticket confirmed) will be shown to the User.

Now from the backend i have to run a PHP file for every 30 seconds Until i get the status Success.

This will be a continuous process.

Can anyone tell me with a good example.

I will be thankful,

Sowmya

8
  • 3
    Use AJAX and poll a PHP script for status every 30 seconds Jun 25, 2013 at 7:07
  • 2
    Cronjob is the way to go ;)
    – user409460
    Jun 25, 2013 at 7:08
  • You can use CRON job, to schedule your task/php page for every 30 seconds.
    – Jahanzeb
    Jun 25, 2013 at 7:09
  • Or just send the email when the backend user changes the status to success?
    – MrCode
    Jun 25, 2013 at 7:09
  • @Darhazer,Jahanzeb Can i expect any example..I am new to those concepts.
    – Sowmya
    Jun 25, 2013 at 7:11

3 Answers 3

18

You are looking for CRON, this helps you to schedule your task at your scheduled time. That is your could execute/run your PHP script at the time scheduled by you.

* * * * * /path/to/php_file
* * * * * sleep 15; /path/to/php_file
* * * * * sleep 30; /path/to/php_file
* * * * * sleep 45; /path/to/php_file

The above cron job will run your php script for every 15 seconds. Here sleep will help to delay the script for every 15 seconds.

1
  • can i expect a example from you..?
    – Sowmya
    Jun 25, 2013 at 7:12
2

There are multiple ways of doing so.

The best way would be using a using a Cron Job.

Other ways are using a webworker or a an AJAX request, but those require a browser to be active at all times.

Here you can find how to set it up.

As for a webworker, it's an HTML 5 feature so it wouldn't be adviced if you expect people using browsers that don't support it.

If your server runs on cPanel, you can easily set up a cron job. Otherwise you'd have to do it through your terminal I think or through your hosting provider if you have paid hosting without cPanel.

You can set up the cron job like this, the command used in the bar is
/path/to/php -q /absolute/path/to/your/phpfile.php >/dev/null

7
  • can i expect a example from you..?
    – Sowmya
    Jun 25, 2013 at 7:12
  • I linked an article for you, check my answer for it.
    – MisterBla
    Jun 25, 2013 at 7:12
  • Yes My server is working on Cpanel. How to set up a corn job using that..?
    – Sowmya
    Jun 25, 2013 at 7:30
  • You go to "Cron Job" under the advanced tab or search for "cron" in the search bar, there you can set it up using Linux commands. It should look like this: imgur.com/C2oItMH
    – MisterBla
    Jun 25, 2013 at 7:45
  • i have my PHP file in this path. www.udoo.in/cron.php Now i am giving the path like below.. home/udoo/public_html/cgi-bin/cron.php >/dev/null Is it correct..?
    – Sowmya
    Jun 25, 2013 at 8:45
1

If you want to just reload your page you can use Javascript to achieve this.

Plain JavaScript

setTimeout(function() {
     window.location.reload();
},  30000);

jQuery

$(function() {
    setTimeout(function() { 
        window.location.reload();
    },  30000);
});

Otherwise, you can use CURL. Visit here to get to know about usage of CURL.

3
  • @Sowmya CRON is also the best option but if you are getting any trouble in setting the cron than you can do it with OMAR's Code.
    – Harshal
    Jun 25, 2013 at 7:22
  • 1
    I would go for the plain JS.
    – Lenin
    Jun 25, 2013 at 7:39
  • But, you should opt for cron to run a script from background.
    – Lenin
    Jun 25, 2013 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.