Cronjobs und PHP

Apache, Lighttpd, nginx, Cherokee
Post Reply
moppi
Posts: 368
Joined: 2003-02-15 11:16
 

Cronjobs und PHP

Post by moppi »

Hallo,

ich habe ein Frage and die Experten ;) wie realisiere ich es am besten PHP Scripte mit dem Cron aus zu führen.

Ich habe PHP als CGI vorliegen, die gleiche Konfiguration wird auch von suPHP genutzt. Leider bekomme ich immer include Fehler und selbst dateien die in der php.ini im include Pfad stehen werden nicht gefunden, wenn ich:

Code: Select all

php -q /pathtoscript/script.php
aufrufe.

Kann mir jemand einen Tipp geben?

Daniel
projekt2501
Posts: 92
Joined: 2003-08-14 08:23
Contact:
 

Re: Cronjobs und PHP

Post by projekt2501 »

Hi,

entweder bemühst du wget und rufst das indirekt über das Internet auf sprich: wget http://meinedomain.tld/meinscript.php oder du kannst auch die scripte entsprechend anpassen und ausführbar machen...

ein beispiel:
in der crontab steht dann als script:

Code: Select all

/pfad/meinscript
das script sieht dann im beispiel so aus(Die erste Zeile ich wichtig!):

Code: Select all

#!/usr/bin/php -q
<?
   echo "ich bin ein script";
?>
Hoffe damit ist dir etwas geholfen...
moppi
Posts: 368
Joined: 2003-02-15 11:16
 

Re: Cronjobs und PHP

Post by moppi »

Ich hatte diese lösung schon einmal irgendwo gesehen wusste aber nicht das es das schon ist. Wenn ich hinzufügen darf, das execute bit des Eigentümers ist noch von nöten ;)

Leider habe ich folgendes Problem immernoch:

Code: Select all

Warning: main(class.ezpdf.php): failed to open stream: No such file or directory in /var/www/localhost/htdocs/web2/html/de/classes/rechnung.function.php on line 22

Warning: main(): Failed opening 'class.ezpdf.php' for inclusion (include_path='.:/usr/lib/php') in /var/www/localhost/htdocs/web2/html/de/classes/rechnung.function.php on line 22

Fatal error: Cannot instantiate non-existent class:  cezpdf in /var/www/localhost/htdocs/web2/html/de/classes/rechnung.function.php on line 45
Rufe ich die Datei über den Browser auf klappt das alles problemlos.
hier kurz ein auszug aus meiner php.ini:

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
include_path = ".:/usr/lib/php:/usr/lib/php/Smarty/:/usr/lib/php/Cpdf"
;
; Windows: "path1;path2"
;include_path = ".;c:phpincludes"
Verzeichnisstruktur:

Code: Select all

rubidium cronjobs # ls -la /usr/lib/php/
total 232
drwxr-xr-x  18 root root  4096 Aug 31 11:14 .
drwxr-xr-x  36 root root 16384 Sep 17 10:53 ..
-rw-r--r--   1 root root     6 Aug 31 09:56 .filemap
-rw-r--r--   1 root root     0 Aug 31 09:56 .lock
drwxr-xr-x   2 root root  4096 Aug 31 09:56 .registry
drwxr-xr-x   2 root root  4096 Jul 22 14:21 Archive
drwxr-xr-x   2 root root  4096 Jul 22 14:21 Console
drwxrwxr-x   3 root root  4096 Aug 31 11:15 Cpdf
drwxr-xr-x   2 root root  4096 Jul 22 14:21 DB
-rw-r--r--   1 root root 33812 Jul 22 14:21 DB.php
-rw-r--r--   1 root root  7839 Jul 22 14:21 HTTP.php
drwxr-xr-x   2 root root  4096 Jul 22 14:21 Mail
-rw-r--r--   1 root root  7331 Jul 22 14:21 Mail.php
drwxr-xr-x   2 root root  4096 Jul 22 14:21 Net
drwxr-xr-x   2 root root  4096 Jul 22 14:21 OS
drwxr-xr-x   4 root root  4096 Jul 22 14:21 PEAR
-rw-r--r--   1 root root 30154 Jul 22 14:21 PEAR.php
drwxr-xr-x   5 root root  4096 Aug 31 09:56 PhpDocumentor
drwxrwxr-x   4 root root  4096 Aug 26 11:42 Smarty
-rw-r--r--   1 root root 17972 Jul 22 14:21 System.php
drwxr-xr-x   3 root root  4096 Jul 22 14:21 XML
drwxr-xr-x   2 root root  4096 Jul 22 14:21 build
drwxr-xr-x   4 root root  4096 Aug 31 09:56 data
drwxr-xr-x   5 root root  4096 Aug 31 09:56 doc
-rw-r--r--   1 root root  9413 Jul 22 14:21 pearcmd.php
-rw-r--r--   1 root root 26767 Jul 22 14:21 run-tests.php
drwxr-xr-x   5 root root  4096 Aug 31 09:56 test
Wie erwähnt das Problem tritt nur auf der Shell oder via Cron Job auf.
Ich habe mal gesehen das es unter

Code: Select all

phpinfo(); 
diese Variable auch mit der Bezeichnung Master und ich glaube Slave gab ob es damit zusammenhängt?
Last edited by moppi on 2004-09-17 19:39, edited 1 time in total.
projekt2501
Posts: 92
Joined: 2003-08-14 08:23
Contact:
 

Re: Cronjobs und PHP

Post by projekt2501 »

wie hast du die Klasse denn eingebunden?

Poste doch mal die Zeile 22 und vielleicht ein bissel drumherum wäre vielleicht hilfreich
moppi
Posts: 368
Joined: 2003-02-15 11:16
 

Re: Cronjobs und PHP

Post by moppi »

Code: Select all

include('class.ezpdf.php');
die 5 zeilen davor und danach sind Kommentare.
projekt2501
Posts: 92
Joined: 2003-08-14 08:23
Contact:
 

Re: Cronjobs und PHP

Post by projekt2501 »

Nimm lieber require_once oder require, je nachdem was Sinn macht.

Dein anderer Fehler will mir grad nicht in den Kopf. Ggf. die Option -C probieren, aber ich glaub nicht, dass es helfen wird.
moppi
Posts: 368
Joined: 2003-02-15 11:16
 

Re: Cronjobs und PHP

Post by moppi »

Problem ergründet, unter gentoo muss es wie folgt heissen:

Code: Select all

#!/usr/bin/php-cgi -q
<?php
  echo "Hello world!";
?>
Dann noch das Owner-Execute Bit setzen und schon funktioniert es.

Vielen Dank
Daniel
Post Reply