12 Replies - 1400 Views - Last Post: 18 March 2013 - 03:08 AM Rate Topic: -----

#1 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

SSH Trouble

Posted 25 February 2013 - 12:40 PM

Good evening, D.I.C.

I don't know if I'm in the right forum, since it's SSH which is giving me trouble, but it's SSH saying that my code is incorrect, therefore, it won't run my cron job.

I created a class which will generate a new code into my system at a regular interval. I've got the cron job set up and everything had been going smoothly. That was until I typed "php /path/to/file.php" then I got an error, reading:

Quote

X-Powered-By: PHP/4.4.9
Content-type: text/html

<br />
<b>Parse error</b>: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/homepages/7/d404100790/htdocs/cron.php</b> on line <b>122</b><br />


That'd be understand, since it tells you which line and stuff the error is on, yes? No.

Here's the line and others around it of where the error is occurring

Posted Image

This is quite annoying, since there's not actually an error. Am I doing something wrong?

Any help greatly appreciated,

Thanks in advanced.

~huzi

Is This A Good Question/Topic? 0
  • +

Replies To: SSH Trouble

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: SSH Trouble

Posted 25 February 2013 - 12:49 PM

  • Why a cron job? It's likely you could accomplish what you're attempting without one.
  • Show us the entire code. What you've posted is incomplete.

Was This Post Helpful? 0
  • +
  • -

#3 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: SSH Trouble

Posted 25 February 2013 - 12:53 PM

View PostCTphpnwb, on 25 February 2013 - 07:49 PM, said:

  • Why a cron job? It's likely you could accomplish what you're attempting without one.
  • Show us the entire code. What you've posted is incomplete.


  • Because I want to generate a new set of redemption codes at a regular interval.
  • See below


My cron.php
//The lines previous to this line are MySQL database functions and information
//The line below is line 120
Class RedeemCode
{
    public $length = 16;
    private $chunk = 4;
    private $space = "-";
    private $prefix = "CHQ";
    private $lastGenerated;
    
    public function Generate() {
        $str = uniqid($this->prefix, false);
        $str = $this->Separate($str);
        
        $this->lastGenerated = $str;
    }
    
    public function Valid($string) {
        return preg_match("/^{$this->prefix}([A-Z0-9]{1})\-([A-Z0-9]{4})\-([A-Z0-9]{{$this->chunk}})\-([A-Z0-9]{{$this->chunk}})$/", $string);
    }
    
    public function Store($worth) {
        if ( empty($this->lastGenerated) ) {
            trigger_error("No key generated.");
        } else {
            //DATABASE INFORMATION
        }
    }
    
    public function Redeem($member, $row) { 
        $val = $row['red_value'];
        //DATABASE INFORMATION
    }
    
    public function Separate($string) {
        $str = "";
        
        for ( $i = 1; $i <= strlen($string); $i++ ) {
            $str .= substr($string, ($i-1), 1);
            if ( $i % $this->chunk == 0 && $i !== strlen($string) ) {
                $str .= "-";
            }
        }
        
        return strtoupper($str);
    }
}

$vals = Array();
for ( $i = 0; $i < 10; $i++ ) {
    $r = rand(5, 10);
    $vals[] = $r*$i;
}

$redeem = new RedeemCode;
$redeem->Generate();
$redeem->Store($vals[rand(0, count($vals)-1)]);



~huzi

This post has been edited by Dormilich: 25 February 2013 - 05:30 PM

Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: SSH Trouble

Posted 25 February 2013 - 01:11 PM

  • I know that you want to make changes at regular intervals, but do you need to? What happens if no one accesses your site today? Do you really need to make changes before the next user logs in? What would be wrong with doing that when they log in?
  • It works for me, but I don't think it's doing what you think it is.

Was This Post Helpful? 0
  • +
  • -

#5 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: SSH Trouble

Posted 25 February 2013 - 01:16 PM

View PostCTphpnwb, on 25 February 2013 - 08:11 PM, said:

  • I know that you want to make changes at regular intervals, but do you need to? What happens if no one accesses your site today? Do you really need to make changes before the next user logs in? What would be wrong with doing that when they log in?
  • It works for me, but I don't think it's doing what you think it is.


I suppose I don't need to do it, I could do it when a user logs in. But still, I'm curious as to why I can't include files or I can't use classes when using SSH. It's a bit annoying. Maybe it's 1and1 excelling as-per-usual.

Thanks for the tips and support.

~huzi
Was This Post Helpful? 0
  • +
  • -

#6 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: SSH Trouble

Posted 25 February 2013 - 01:27 PM

Two things to consider:

1) When you see a parse error on a line that clearly does not contain a parse error, that means that the actual error is earlier in the file. In other wods, the portion you omitted is almost certainly where the error lies.
2) It's quite possible that PHP runs in a different context when used in cron jobs versus web pages. For instance, it may run under a different use account and may use a different php.ini file. So just because something works via a web request doesn't guarantee it'll work in a cron job.
Was This Post Helpful? 2
  • +
  • -

#7 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5959
  • View blog
  • Posts: 23,229
  • Joined: 23-August 08

Re: SSH Trouble

Posted 25 February 2013 - 02:19 PM

Quote

2) It's quite possible that PHP runs in a different context when used in cron jobs versus web pages. For instance, it may run under a different use account and may use a different php.ini file. So just because something works via a web request doesn't guarantee it'll work in a cron job.


This is absolutely true. There is likely even a completely different configuration file associated with the CLI version of PHP.

Quote

X-Powered-By: PHP/4.4.9


Ouch! Why so old? Wonder if that's the issue. In fact, I'm nearly sure it is. Are you using PHP5 for the web site?
Was This Post Helpful? 1
  • +
  • -

#8 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: SSH Trouble

Posted 25 February 2013 - 02:22 PM

Thanks a lot for your replies. It's clearly understandable. The problem is, if I remove the class and make it into functions, the file wouldn't have any errors. Like JackOfAllTrades menthioned, it is more than likely something different for the configuration.

Oh well. Thanks again!

~huzi
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5959
  • View blog
  • Posts: 23,229
  • Joined: 23-August 08

Re: SSH Trouble

Posted 25 February 2013 - 02:27 PM

It is definitely the version there. Check my edit.
Was This Post Helpful? 0
  • +
  • -

#10 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: SSH Trouble

Posted 25 February 2013 - 03:24 PM

View PostJackOfAllTrades, on 25 February 2013 - 04:19 PM, said:

Quote

X-Powered-By: PHP/4.4.9


Ouch! Why so old? Wonder if that's the issue. In fact, I'm nearly sure it is. Are you using PHP5 for the web site?

Great catch! I didn't even notice the version number. That's definitely the issue - the code is using the public/private visibility modifiers. Those were introduced in PHP 5. So if the code is running on a PHP 4 interpreter, using them will generate parse errors because those keywords didn't exist in that version.

So the fix is simply to reconfigure the host to run the cron job with a PHP 5 interpreter. And if that's not an option, get a better host. Seriously, PHP 5 has been out for over 8 years now - there's no reason to be writing new code for PHP 4.
Was This Post Helpful? 1
  • +
  • -

#11 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: SSH Trouble

Posted 25 February 2013 - 04:55 PM

View PostAdaHacker, on 25 February 2013 - 10:24 PM, said:

View PostJackOfAllTrades, on 25 February 2013 - 04:19 PM, said:

Quote

X-Powered-By: PHP/4.4.9


Ouch! Why so old? Wonder if that's the issue. In fact, I'm nearly sure it is. Are you using PHP5 for the web site?

Great catch! I didn't even notice the version number. That's definitely the issue - the code is using the public/private visibility modifiers. Those were introduced in PHP 5. So if the code is running on a PHP 4 interpreter, using them will generate parse errors because those keywords didn't exist in that version.

So the fix is simply to reconfigure the host to run the cron job with a PHP 5 interpreter. And if that's not an option, get a better host. Seriously, PHP 5 has been out for over 8 years now - there's no reason to be writing new code for PHP 4.


I attempted to update my PHP version through my control panel, but all I saw was this

Posted Image

Quite confusing.. :sarcasm:

Thanks for your suggestions!

~huzi
Was This Post Helpful? 0
  • +
  • -

#12 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5959
  • View blog
  • Posts: 23,229
  • Joined: 23-August 08

Re: SSH Trouble

Posted 25 February 2013 - 04:58 PM

Check for multiple versions of PHP in your path. If you find one that is 5+, then ensure you use that one.
Was This Post Helpful? 1
  • +
  • -

#13 huzi8t9  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 326
  • Joined: 11-July 07

Re: SSH Trouble

Posted 18 March 2013 - 03:08 AM

View PostJackOfAllTrades, on 25 February 2013 - 11:58 PM, said:

Check for multiple versions of PHP in your path. If you find one that is 5+, then ensure you use that one.


I realised that whilst I were using the command "php /path/to/file.php", I should have used "php5 /path/to/file.php"

Thank you all for your replies! You've saved me.

Many thanks

~huzi
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1