Jump to content

help with realtime php things..


UnknownPlayer

Recommended Posts

It would be interesting to know what, specifically, you want it to do. But, yes, it is possible. Look running "cron" jobs. There's too much to try to explain in a forum post - especially when there are many resources readily available.

Link to comment
Share on other sites

WHEN time is 00:00? Generally, no.

 

IF time is 00:00, yes.

 

PHP isn't a language that waits for events. It can check if an event has happened upon execution though.

 

Which is why there are things such as CRON which can be used WHEN a specific time occurs.

Link to comment
Share on other sites

Technically it is not possible IN php.

You can schedule a php script to run through the cli process at 00:00 with cron on unix-like systems or with Scheduled Tasks on windows.

Either way, we would need a little more info before offering a significant solution.

Link to comment
Share on other sites

all you have to do is write a script that disables voting... then go to cpanel's crontab entry and tell it to run everyday at 00:00.  You don't have to put the time in your PHP code.

 

It should look something like this

0    0    *    *    *        disablevoting.php

 

but you don't want disablevoting.php to be available to the public, you might want to put it out of the web root.

Link to comment
Share on other sites

Think of it this way.  Without the use of crontabs, it would be no different that having someone go run the same errand for you over and over and do nothing about it until midnight.... and then continue to run the fake errand again until the next midnight.  It's really a waste of effort, energy and time.  Especially when you have the option, all the while, to send this errand person out ONLY at midnight.

Link to comment
Share on other sites

I've actually made this happen in plain PHP and HTML. (the code for it is below)

 

It basically checks the current time for the wanted one.

 

So lets day we have a variable named $currentTime which is whatever the time it is.

The next variable is $wantedTime, which is, in your case, 00:00.

 

I ran a check if $currentTime equals $wantedTime every time the page refreshes. (I used meta content refresh every 59 seconds, which isn't good, but in my case, it did the justice).

 

When the time equaled one another, it redirected to another page.

 

EDIT: (heres the code) - Save this as index.php and change the anotherPage.php to your wanted page with execution. Or you can execute it on the first if statement.

<?php
$wantedTime = "00:00";
$currentTime = date("H:i");

echo "The time is: $currentTime<br />";
echo "Script will execute at $wantedTime<br />";

if($currentTime == $wantedTime)
{
echo '<meta http-equiv="refresh" content="0; url=anotherPage.php">';
}
else
{
echo '<meta http-equiv="refresh" content="50;url=index.php">';
}


$to = strtotime($wantedTime);
$from = strtotime($currentTime);
$calculation = round(abs($to - $from) / 60,2);

echo "<br />The code will execute in $calculation minutes";

?>

Link to comment
Share on other sites

I've actually made this happen in plain PHP and HTML.

 

What it did was, to check the time for the specified one.

 

So lets day we have a variable named $currentTime which is whatever the time it is.

The next variable is $otherTime, which is, in your case, 00:00.

 

I ran a check if $currentTime equals $otherTime every time the page refreshes. (I used meta content refresh every 55 seconds, which isn't good, but in my case, it did the justice).

 

When the time equaled one another, it redirected to another page.

Yes, but that method will only work if your page is visited everyday... and especially at midnight.

Link to comment
Share on other sites

I've actually made this happen in plain PHP and HTML. (the code for it is below)

 

It basically checks the current time for the wanted one.

 

So lets day we have a variable named $currentTime which is whatever the time it is.

The next variable is $wantedTime, which is, in your case, 00:00.

 

I ran a check if $currentTime equals $wantedTime every time the page refreshes. (I used meta content refresh every 59 seconds, which isn't good, but in my case, it did the justice).

 

When the time equaled one another, it redirected to another page.

 

EDIT: (heres the code) - Save this as index.php and change the anotherPage.php to your wanted page with execution. Or you can execute it on the first if statement.

<?php
$wantedTime = "00:00";
$currentTime = date("H:i");

echo "The time is: $currentTime<br />";
echo "Script will execute at $wantedTime<br />";

if($currentTime == $wantedTime)
{
echo '<meta http-equiv="refresh" content="0; url=anotherPage.php">';
}
else
{
echo '<meta http-equiv="refresh" content="50;url=index.php">';
}


$to = strtotime($wantedTime);
$from = strtotime($currentTime);
$calculation = round(abs($to - $from) / 60,2);

echo "<br />The code will execute in $calculation minutes";

?>

 

NOTE: In this code I used a 24 hour system while you probably need a 12 hour one. If thats the case, replace the capital H to a small h.

Link to comment
Share on other sites

I've actually made this happen in plain PHP and HTML.

 

What it did was, to check the time for the specified one.

 

So lets day we have a variable named $currentTime which is whatever the time it is.

The next variable is $otherTime, which is, in your case, 00:00.

 

I ran a check if $currentTime equals $otherTime every time the page refreshes. (I used meta content refresh every 55 seconds, which isn't good, but in my case, it did the justice).

 

When the time equaled one another, it redirected to another page.

Yes, but that method will only work if your page is visited everyday... and especially at midnight.

 

Sorry for the double post.

 

Correct, the page has to be opened by atleast one user, in my case I had this page opened at all time at atleast one computer.

Link to comment
Share on other sites

Keeping it open will not do any good.

The only way it would do any good is if you refreshed the page every minute.. on the minute.  Which you can easily script it to do, but it would probably slow your server down quite a bit... possibly to where you need to restart apache.

Link to comment
Share on other sites

Keeping it open will not do any good.

The only way it would do any good is if you refreshed the page every minute.. on the minute.  Which you can easily script it to do, but it would probably slow your server down quite a bit... possibly to where you need to restart apache.

 

Its exactly what my script posted above does. It refreshes the page every minute and checks if the value is a match yet.

 

One refresh per minute equals a 1440 times refreshed page per day, which would equal 1440 visitors per day. I hope apache wouldn't need to be restarted for that small amount of hits.

 

(I made it refresh every 50 seconds, so that would make it refresh 1200 times, which is even less than 1440.)

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.