• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question script works from browser but not as cron job

brownbag

Basic Pleskian
I've got a script that creating a pdf file from data in my database and sends a report via email. It works perfectly fine when run from a browser but fails when I run it as a cron job (Plesk scheduled task).

I've narrowed the issue down to the first few lines of code by creating a stripped down version of the script that also has the same behaviour. The total content of the file is four lines, as below:

PHP:
ob_start();
require '/var/www/vhosts/mydomain.com/customer/sm/inc/_global/db_con.php';
require '/var/www/vhosts/compleit.com/customer/test/fpdf/pdf_mc_table.php';
echo "ok";

The script fails with the errors below:

Code:
PHP Warning: require(../fpdf/pdf_mc_table.php): failed to open stream: No such file or directory in /var/www/vhosts/compleit.com/customer/test/cron/data_check2.php on line 5
PHP Warning: require(../fpdf/pdf_mc_table.php): failed to open stream: No such file or directory in /var/www/vhosts/compleit.com/customer/test/cron/data_check2.php on line 5
PHP Fatal error: require(): Failed opening required '../fpdf/pdf_mc_table.php' (include_path='.:/opt/plesk/php/7.3/share/pear') in /var/www/vhosts/...

Of course the pdf_mc_table.php file is located in the specified location.
TIA
 
I did try adding hte following into php.ini but it didn't help:

include_path = ".:/var/www/vhosts/compleit.com/customer/test/fpdf"

However it didn't help.
 
hello @brownbag ,

I gues you are using correct type of task - php script (just in case)

requires should contain path from subscription root:
let's say I have mysubscr.tld with additional domain mydomain.tld with doc root mydomaintld

at the webroot of mydomain.tld I have files test/php/test.php and tst2/i.php

then i.php should contain something

PHP:
require 'mydomaintld/test/php/test.php';
 
hello @brownbag ,

I gues you are using correct type of task - php script (just in case)

requires should contain path from subscription root:
let's say I have mysubscr.tld with additional domain mydomain.tld with doc root mydomaintld

at the webroot of mydomain.tld I have files test/php/test.php and tst2/i.php

then i.php should contain something

PHP:
require 'mydomaintld/test/php/test.php';
Yes, I am using php script as the task type.

My other cron jobs use the full reference as I've used in this script and work fine. In fact, even this one works on the first require (for db_con.php) but only fails on the second one.
When I change it to your suggestion it no longer works, even when run from the browser. So I don't think you've got the solution there. :(
 
@brownbag ,

is shell access enabled for domain system user or shell access is turned off for it?

is your script placed in one domain space but you want to call it from another domain from different subscription ?
or both domains related to the same subscription (and utilize the same system user)?

or you have one cronjob for domain mydom.tld, that works fine
and try to configure another one cron job(similar to first one) for the same domain but it does not work ?


it looks like you have two different subscriptions mdom1.tld and mdom2.tld (which utilize different system users).

so, when you tries to configure cronjob for mdom2.tld that should invoke files that are placed at mdom1.tld web space - it won't work due to lack of permissions (and this is correct).
To make it work you need to copy all required files to the mdom2.tld web space (don't forget set correct owner for files if you would do this under root!).

another way - both this domains should be in the same subscription (with the same system user)
 
Thanks Nik for your reply. The script is actually as follows:
PHP:
ob_start();
require '/var/www/vhosts/mydomain.com/customer/test/inc/_global/db_con.php';
require '/var/www/vhosts/compleit.com/customer/test/fpdf/pdf_mc_table.php';
echo "ok";
I just couldn't find a way to edit my post after noticing it and didn't think it would make much difference.

I do have many cron jobs - most just require db_con.php but it's when one requires the pdf_mc_table.php that it comes unstuck.
 
what is the web space folder of the domain for which you are trying to configure the cron task ?

what owner and permissions of this folder above and for pdf_mc_table.php file?
 
Now I see another typo. this is correct!

PHP:
ob_start();
require '/var/www/vhosts/mydomain.com/customer/test/inc/_global/db_con.php';
require '/var/www/vhosts/mydomain.com/customer/test/fpdf/pdf_mc_table.php';
echo "ok";
 
what is the web space folder of the domain for which you are trying to configure the cron task ?

what owner and permissions of this folder above and for pdf_mc_table.php file?
The cron job is in /var/www/vhosts/mydomain.com/customer/test/cron/

The permissions of the fpdf folder are 755
The permissions of the file are 644

This is the same as the permissions of the _global folder and db_con.php file - for which I have no problem.

So I don't think it's a permissions problem (that was the first thing I checked as the error did suggest it may be the issue).
 
@brownbag ,
did you try code like below:
PHP:
ob_start();
require 'customer/test/inc/_global/db_con.php';
require 'customer/test/fpdf/pdf_mc_table.php';
echo "ok";
?

please have in view, that it won't work through the web, but should work as cron job
 
OK, I tried this and yes, you're right that it doesn't work through the web - neither require work and in the cron job the require db_con.php still works.
But I get the same error with pdf_mc_table.php
 
@brownbag ,

could you please provide output of
Code:
ls -ld customer/test/fpdf/ customer/test/fpdf/pdf_mc_table.php
executed from /var/www/vhosts/mydomain.com/ under root ?
 
damn. it should work but it does not...

let's summarize:
you have bunch of scripts like
Code:
customer/test/inc/_global/db_con.php
customer/test/fpdf/ customer/test/fpdf/pdf_mc_table.php
customer/test/cron/crontask.php
in your subscription web space, which have correct owner and permissions.

the crontask.php contains code like below:
PHP:
ob_start();
require 'customer/test/inc/_global/db_con.php';
require 'customer/test/fpdf/pdf_mc_table.php';
echo "ok";

in your subscription mydomain.com you trying to configure cron job that should execute crontask.php (script type is set as php and path to it was shosen with Plesk UI)

however, when it executed (or by button run now) it returns errors (btw, are they staying same or were changed since your first message)
that there is no such file/directory or stream.


to find root cause an access to your server needed. So I recommend you submit ticket to the Plesk technical support.
 
damn. it should work but it does not...

let's summarize:
you have bunch of scripts like
Code:
customer/test/inc/_global/db_con.php
customer/test/fpdf/ customer/test/fpdf/pdf_mc_table.php
customer/test/cron/crontask.php
in your subscription web space, which have correct owner and permissions.

the crontask.php contains code like below:
PHP:
ob_start();
require 'customer/test/inc/_global/db_con.php';
require 'customer/test/fpdf/pdf_mc_table.php';
echo "ok";

in your subscription mydomain.com you trying to configure cron job that should execute crontask.php (script type is set as php and path to it was shosen with Plesk UI)

however, when it executed (or by button run now) it returns errors (btw, are they staying same or were changed since your first message)
that there is no such file/directory or stream.


to find root cause an access to your server needed. So I recommend you submit ticket to the Plesk technical support.
will do. thanks.
 
Back
Top