leonep

Well-Known Member
Nov 18, 2014
189
13
68
Pescara
cPanel Access Level
Root Administrator
Hi ,
I am trasfering a web project to my Cpanel hosting. i got problem with a php cron script that uses php header location redirect.
the cron php script interrupts and redirect not work on destination page.
The customer told me that on previous hosting works fine ( with same php file )
this my problem? can i make some sort of workaround to fix it?
thanks
 

leonep

Well-Known Member
Nov 18, 2014
189
13
68
Pescara
cPanel Access Level
Root Administrator
of course.... i have a scheduled job:
0 * * * * /usr/local/bin/php /home/queenhostel/public_html/it/script_cron/script_cron_1_step.php

and the file inside is:
Code:
<?php
...
....
...

header('Location: /usr/local/bin/php/home/queenhostel/public_html/it/script_cron/script_cron_2_step.php');
?>
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
466
113
UK
cPanel Access Level
Root Administrator
Is it possible that the cron job called the php file using a curl or wget command on the previous server ?

When a PHP script is run directly from a cron job, there is no HTTP header request, so it often can't redirect that request to your 2_step file, as there was nothing to redirect. Calling via curl or wget might solve that.
 

leonep

Well-Known Member
Nov 18, 2014
189
13
68
Pescara
cPanel Access Level
Root Administrator
Is it possible that the cron job called the php file using a curl or wget command on the previous server ?
i have personal transfered web project via ftp and there is no changes

but you 're right i have read that a lot of people have the same problem and they have used cURL or wget

i don't know if previous hosting (aruba.it) uses another task manager or some restriction on my server block redirect (shell_exec for example)

As long as this is redirecting to the correct location I don't see why it wouldn't work. What is the specific error you're receiving?
where i can found execution logs?

thanks for help !
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
466
113
UK
cPanel Access Level
Root Administrator
I should have spotted it before - but maybe it's a typo when you entered it on this forum:
In your code
header('Location: /usr/local/bin/php/home/queenhostel/public_html/it/script_cron/script_cron_2_step.php');
It looks like there is a space missing between ~/php and /home eg
Code:
header('Location: /usr/local/bin/php /home/queenhostel/public_html/it/script_cron/script_cron_2_step.php');
If there is no space, the path will never resolve. I am also not at all sure you should be repeating the call to the PHP CLI binary here either.
 
Last edited:

leonep

Well-Known Member
Nov 18, 2014
189
13
68
Pescara
cPanel Access Level
Root Administrator
I try billions of paths .. maybe i paste here a wrong 1 .
I want understand this problem just for curiosity because my customer used cURL with success ...

apparently i have no errors or i am not good find 8)
where can i start troubleshooting this problem?
thanks for help
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
466
113
UK
cPanel Access Level
Root Administrator
I don't think that your issue with the PHP header("Location: xxx"); function is anything to do with cPanel.

A forum specialising in PHP would probably be more useful in explaining it all to you.

For what i's worth, my understanding of the header("Location: xxx"); function is that it sends a a location back to the browser, and returns a redirect (302) code (unless some other code has been explicitly set) and this code must be sent to the browser before any other HTML or text is output.

Since the call was made by the php binary called from cron, using the header function may not be relevant in your case - probably you should use an include or a meta refresh redirect as discussed in the stackoverflow thread here : stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php especially if the call is made on the basis of the result of a state test, or as an ongoing process.

Further information on the header function available from PHP: header - Manual and from PHP header() Function

Hope this helps.
 
  • Like
Reactions: cPanelLauren