[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cron Job Issue

Posted on 2011-10-18
6
Medium Priority
?
330 Views
Last Modified: 2012-05-12
I had a cron job running on a linux server with:
Debian 5.0 - Plesk 9.3 - RAID1 - 64bit

I duplicated the application to a new linux server using:
Parallels Plesk Panel v10.3.1_build1012110812.15 os_CentOS 5

The cron job ran perfect on the first server.  Now, I am getting PHP Notice: Undefined Index for HTTP_HOST and some other Server variables......

This is an email cron that picks up scheduled email jobs out of a table and mails out newsletters.  I am using a PHP class that relies on the server variables.

Can anyone explain why on one linux server it works on on another it dosn't?
0
Comment
Question by:kageboy2003
  • 3
  • 2
6 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36989924
There are several reasons.  The first is that the server admin can change what server variables are reported.  Second is that different version of the different web servers report different variables anyway.  Third is that the 'php.ini' used by command line programs is often different than the one used on the web server.

You can run the PHP page below on the two servers and on the command line to see what server variables are reported.  That will tell you what is available in each situation.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PHP Server Variables</title>
</head>
<body><h1>PHP Server Variables</h1>
<?php

//reset($_SERVER);
foreach($_SERVER as $key => $value) {
    echo "<b>$key :</b> $value<br />\n";
}

?>
</body>
</html>

Open in new window

0
 
LVL 19

Expert Comment

by:xterm
ID: 36990168
It could be because on the 2nd server, register_globals = Off in php.ini (where it was On on the first server.)

Try using $_SERVER['HTTP_HOST'] to access it, and see if your luck changes.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36990866
FYI, I just ran my program above from the command line on IIS and on Apache.  None of the 'normal' $_SERVER variables show up on either one.  This is actually not surprising because it is not running thru the web server when invoked from the command line.  What does show up are a lot of 'environment variables'.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36991918
If you want to see what PHP knows about in the CRON job, you can install this as a cron job and trigger it.  Untested code but valid in principle.  I have dealt with what you are facing and I recall that after I could see the variables things got easier very fast.  Best of luck, ~Ray
<?php // RAY_cron_display.php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);
ob_start();
phpinfo();
$msg = ob_get_contents();
mail('You@Your.org', 'Cron Output', $msg);

Open in new window

0
 
LVL 19

Accepted Solution

by:
xterm earned 1000 total points
ID: 36992892
Well, how are you running this cron?   If you're simply calling "php /path/to/page.php" via cron, of course all the SERVER variables will be empty, because you're not using the Apache server.  You can't get HTTP_HOST and REQUEST_URI when there was no HTTP GET.

If the web page relies on knowing how and where its called, you might consider instead setting a cron which uses wget or curl to go through actual http to retrieve the page as a mock browser client, and then the SERVER variables will be populated.
0
 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 1000 total points
ID: 36994298
I agree with @xterm.  This little program below will run the program above thru the web server where it will see the $_SERVER variables.  If your page will run correctly on the web server thru a browser, you can use this technique to run it from the command by 'calling' it to run on the web server.  Using 'http' method in file_get_contents() turns it into a browser-like request to the page on the web server.
<?php 
// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

$pgcntent = file_get_contents("http://10.202.46.40/servari.php");
echo $pgcntent;
 ?>

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question