Ok! So here is what I'm trying to accomplish... Lets call the file test1.php Using file_get_contents i'm fetching data from one site and inserting it into another database in a loop of 3 sec because it takes 1 sec to fetch and store so with another 1 sec buffer I'm hoping to get data that's no older than 5 secs. The file works on my localhost/test1.php just fine.. on my local I add a java script to refresh the browser... If i replace my $con settings to my server, and hit the file on my local browser using wamp that works too.. the problem begins when I upload it on my server and add it as a cron, hitting it just once in the morning and letting it run all day the loop works while the values it returns are null.
Things you may want to know...
1) My apache server mods enabled are the same as those on my wamp (curl installted, php 5.5.9 allow_url_fopen = On allow_url_include = Off)
2) Apache Mods
3) Code
<?php
$con=mysqli_connect("localhost","user","pwd","dbname");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$open_time=strtotime('07:00:00');
$close_time=strtotime('23:55:00');
$current_time=strtotime(date('H:i:s'));
/***************** End Timing ********************/
if($current_time >= $open_time && $current_time<=$close_time) {
while ($current_time < $close_time) {
// Perform queries
$dataQuery = mysqli_query(); //my query goes here
while($row = $dataQuery->fetch_assoc())
{
$data = @file_get_contents();
$insert = mysqli_query(); //insert this data into my db
}
sleep(3);
}
mysqli_close($con);
}
?>
4) The different ways I've tried to execute the cron :p
php /home/domain/public_html/test1.php php5 /home/domain/public_html/test1.php php /home/domain/public_html/test/test1.php /usr/bin/php -q /home/domain/public_html/test1.php /usr/bin/php -q /home/domain/fcgid/test1.php
5) The link to file get redirects to https (I'm still trying to see if its affecting anything... but I'm more inclined to rule this point out as the link works and stops randomly.)
6) After fixing all errors the file returns no output, which could also mean there are no errors (or they're emailed to me)
7) When it does work for a while, it will fetch values for a while, but stops after 2-3hrs, I can see its created several connections that are idle/sleep. It freezes mysql, and sometimes maxes out the server resources. Even rebooting doesn't help, values inserted after reboot are nulls and 0's
8) I'm still playing with max_execution_time .. I've currently set to 61,200 secs (17hrs) I'm also simultaneously running the same test on another sever with max_execution_time set to 60 and the cron hitting the file every 60 secs
9) Like i said before, if I hit the file locally on my windows system it works like its supposed (after switching $con details to my server)I add a javascript and open it in firefox/chrome localhost/test1.php
Help me please!
************My Questions************** 1) What am I doing wrong, and how would you recommend I go about doing this task. 2) What all do i need enabled/disabled on my apache/php/ 3) Is there a better way of doing the same thing?