Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How do I run Multiple php files with just one PHP File?

errors with php and mysql

5:56 am on Jun 10, 2012 (gmt 0)

New User

5+ Year Member

joined:June 10, 2012
votes: 0

Hello I am trying to figure out how I can create a cron job for file "update.php" that when it runs it, it will then try to run 12 other php files I have.. PLUS a data base file...

Currently I am doing this.. BUT I am receiving a lot of errors and the scritp stops running...

update.php file

error_reporting(E_ALL);ini_set('displa… 1);

require_once ("getAquarius.php");
require_once ("getAries.php");
require_once ("getCancer.php");
require_once ("getGemini.php");
require_once ("getLeo.php");
require_once ("getLibra.php");
require_once ("getPisces.php");
require_once ("getSagittarius.php");
require_once ("getScorpio.php");
require_once ("getTaurus.php");
require_once ("getVirgo.php");


EACH of the 12 files does the same thing..

$url = "http://my.horoscope.com/astrology/free-…
$start_text2 = '<div class="fontdef1" style="padding-right:10px;" id="textline">';
$end_text2 = '<div align="right">';
$source2 = file_get_contents($url);
$start_pos2 = strpos($source2, $start_text2) + strlen($start_text2);
$end_pos2 = strpos($source2, $end_text2) - $start_pos2;
$content = substr($source2, $start_pos2, $end_pos2);
$scopeid = rand(10000, 600000);
$text = dbPrepare(trim(strip_tags($content)));
$scopeFriendsOne = rand(1, 4);
$scopeFriendsTwo = rand(5, 7);
$scopeFriendsThree = rand(9, 12);
$randNumOne = rand(0,18);
$randNumTwo = rand(19,32);
$randNumThree = rand(33,48);
$randNumFour = rand(49,61);
$randNumFive = rand(62,80);
$randNumSix = rand(81,100);
$luckynumbers = $randNumOne.",".$randNumTwo.",".$randNum…
$starsLove = rand(1, 5);
$starsMoney = rand(1, 5);
$starsHealth = rand(1, 5);
$starsCareer = rand(1, 5);
$starsNumbers = $starsLove.",".$starsMoney.",".$starsMon…
mysql_query("INSERT INTO Aquarius (scopeid, horoscope, friendone, friendtwo, friendthree, luckynumbers, stars) VALUES ($scopeid, '".$text."', $scopeFriendsOne, $scopeFriendsTwo, $scopeFriendsThree, '".$luckynumbers."', '".$starsNumbers."')");

AND here is the db.php that each file is requiring


$dbname = "SITENAME"; //dbname
$dbhost = "LOCALHOST";
$dbuser = "USERNAME";
$dbpass = "PASSWORD";

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $conn);

function dbPrepare($str){
$str = mysql_real_escape_string($str);
return $str;

When cron runs the update.php file to get the infromation and post it into my database, I then get and error and the cron/update.php file stops running..

I could create a cron file for each of the php files but my hosting server (GoDaddy) only allows me to have 10 cron files..

BASICALLY I am wanting the crop job to execute update.php at a specific time and when it runs it I want the update.php file to open the first php file do its thing then close it and move on to the next file and so on an so forth till all 12 files have run...

IF anyone can help please that would be great
12:49 pm on June 10, 2012 (gmt 0)

Administrator from US 

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 25, 2005
votes: 99

Does the script run when you run it via a browser normally?

What errors does it get when you run via the cron?

Have you tried running it via CURL from the cron so it has a full CGI environment such as "curl http://www.example.com/update.php"?
4:33 pm on June 11, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
votes: 0

Another thing you'll need to do is incorporate strong error trapping into any programming you have here. Here's how I know you haven't done that:

mysql_query("[your select statement]");

For every command you execute, error trap it and do something useful if it errors.

mysql_query("[your select statement]") or log_and_notify(mysql_error());

Where "log_and_notify([message])" is a function you write that writes the error message to a log and optionally emails you of the error.

The next step is review your programming for dependencies. An example is if the previous doesn't execute properly, it will cause other errors.

if (mysql_query("[your select statement]")) {

// OK, it executed, let the program continue

else {
// Do other stuff in an error condition

See that? Some things won't work, but your script won't stop completely, it will go on to the next task.