News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

PHP Undefined Index Notices in Subs-Post.php

Started by sah62, January 25, 2014, 09:54:52 PM

Previous topic - Next topic

sah62

I first described this issue in a support thread: http://www.simplemachines.org/community/index.php?topic=517365.0

I'm reporting it here based on the feedback provided by Sir Cumber-Patcher:

http://www.simplemachines.org/community/index.php?topic=517365.msg3660011#msg3660011

I'm consistently getting these PHP error notices in a file named php_errors.log in my forum's home directory when the "Send Birthday Emails" scheduled task runs automatically:


[22-Jan-2014 23:04:19 UTC] PHP Notice:  Undefined index: server in /public_html/forum/Sources/Subs-Post.php on line 622
[22-Jan-2014 23:04:19 UTC] PHP Notice:  Undefined index: character_set in /public_html/forum/Sources/Subs-Post.php on line 1229
[22-Jan-2014 23:04:19 UTC] PHP Notice:  Undefined index: character_set in /public_html/forum/Sources/Subs-Post.php on line 1229
[22-Jan-2014 23:04:19 UTC] PHP Notice:  Undefined index: character_set in /public_html/forum/Sources/Subs-Post.php on line 1229
[22-Jan-2014 23:04:19 UTC] PHP Notice:  Undefined index: utf8 in /public_html/forum/Sources/Subs-Post.php on line 1272
[22-Jan-2014 23:04:19 UTC] PHP Notice:  Undefined index: utf8 in /public_html/forum/Sources/Subs-Post.php on line 1274
[22-Jan-2014 23:04:19 UTC] PHP Notice:  Undefined index: character_set in /public_html/forum/Sources/Subs-Post.php on line 1229



Line 622: $line_break = $context['server']['is_windows'] || !$use_sendmail ? "\r\n" : "\n";

Line 1229: $charset = $custom_charset !== null ? $custom_charset : $context['character_set'];

Line 1272: if ($hotmail_fix && ($context['utf8'] || function_exists('iconv') || $context['character_set'] === 'ISO-8859-1'))

Line 1274: if (!$context['utf8'] && function_exists('iconv'))


Versio of SMF: 2.0.7

Mods:
ENotify 2.0.2
SMF 2.0.7 Update 1.0
Simple Audio Video Embedder 2.3
SMF 1.1.19 / 2.0.6 Update 1.0
SMF 2.0.5 Update 1.0
SMF 2.0.4 Update 1.0
SMF 2.0.3 Update 1.0
Auto Purge Old Topics 1.3
KeyCAPTCHA for SMF 2.3
AjaxChat Integration 3.3b
Show Joined, Location, Username In Topic View 1.0
PM Status    1.0
SMF 2.0.2 Update 1.0
SMF 2.0.1 Update 1.0
No Reply Emails 1.3.8
RSS Feed Icon   1.1
MessagePreviewOnHover 1.8

Themes: core, default

Are you using UTF-8? Yes

What caching level are you using? Level 1

Server Software: Linode VPS server running Ubuntu 12.04 LTS. My web server is nginx/1.1.19, PHP version is 5.3.10-1ubuntu3.9.

How to Reproduce this Error?: Modify a user's profile to include a birthday on the current date. Schedule the "Send Birthday Emails" task to run at a specific time. Let the task run automatically when the scheduled time arrives. In my case the email is sent and the PHP notices are logged. The notices are not generated when the task is run manually.

Arantor

Here's the thing... if it were a genuine bug it would affect everyone who has that functionality enabled - but it doesn't. So it's almost certainly more specific to your installation...

sah62

Quote from: Sir Cumber-Patcher on January 25, 2014, 10:16:32 PM
So it's almost certainly more specific to your installation...

Is there something I can do to debug this on my end?

Arantor

That's the thing, I'm not sure how I'd begin to debug that - because it's not happening on other forums.

See, here's the thing... by rights if birthday emails is broken, ALL emails from scheduled tasks should be similarly broken. You've got no mods that, as far as I can see, should affect this.

Looking at the code, it really does look like it should be very broken for all scheduled tasks sending emails, not just that one. There is only one place $context['server'] is set (which is the same place $context['utf8'] etc. is primarily defined) and that's in loadTheme() but loadTheme should never be called during the scheduled tasks. So I'm confused how it could have ever worked because I can't see any sign that it can. :(

emanuele



Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Arantor

Here's the thing... aside from the fact that scheduled tasks should never be triggered by anyone but users (since it requires local JS), the code path in 2.0 never actually calls loadTheme so those variables never get loaded anyway as far as I can see... and yet it must be for the majority of the time because it's not broken for all scheduled tasks that send email and it's not a widespread problem.

emanuele

Quote from: Sir Cumber-Patcher on January 30, 2014, 11:04:37 AM
Here's the thing... aside from the fact that scheduled tasks should never be triggered by anyone but users (since it requires local JS)
Not true. Scheduled tasks are also triggered by "is_robot" (or whatever, I keep forgetting its name) directly, without javascript.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Arantor

The only place index.php?scheduled seems to be called is:

$context['html_headers'] .= '
<script type="text/javascript">
function smfAutoTask()
{
var tempImage = new Image();
tempImage.src = "' . $scripturl . '?scheduled=' . $type . ';ts=' . $ts . '";
}
window.setTimeout("smfAutoTask();", 1);
</script>';


If it can be triggered *anywhere* else, I'd love to know about it.

emanuele

if (isBrowser('possibly_robot'))
{
// @todo Maybe move this somewhere better?!
require_once($sourcedir . '/ScheduledTasks.php');

// What to do, what to do?!
if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
AutoTask();
else
ReduceMailQueue();
}
else
{
$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];

addInlineJavascript('
function smfAutoTask()
{
var tempImage = new Image();
tempImage.src = smf_scripturl + "?scheduled=' . $type . ';ts=' . $ts . '";
}
window.setTimeout("smfAutoTask();", 1);');

}


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Arantor

Even though that's 2.1 code, your argument still doesn't work.

Because in 2.0 (which is what this report covers)... that code is *after* where $context['utf8'] etc. is defined because it's at the end of loadTheme, so all the undefined variables would be declared at that point.

In any case the original linked topic clearly shows it going through index.php?scheduled rather than from possibly_robot.

sah62

#10
I'm still seeing this issue in 2.0.8. Any diagnostic help would be appreciated.


[22-Jul-2014 22:02:00 UTC] PHP Notice:  Undefined index: server in /public_html/forum/Sources/Subs-Post.php on line 627
[22-Jul-2014 22:02:00 UTC] PHP Notice:  Undefined index: character_set in /public_html/forum/Sources/Subs-Post.php on line 1234
[22-Jul-2014 22:02:00 UTC] PHP Notice:  Undefined index: character_set in /public_html/forum/Sources/Subs-Post.php on line 1234
[22-Jul-2014 22:02:00 UTC] PHP Notice:  Undefined index: character_set in /public_html/forum/Sources/Subs-Post.php on line 1234
[22-Jul-2014 22:02:00 UTC] PHP Notice:  Undefined index: utf8 in /public_html/forum/Sources/Subs-Post.php on line 1277
[22-Jul-2014 22:02:00 UTC] PHP Notice:  Undefined index: utf8 in /public_html/forum/Sources/Subs-Post.php on line 1279
[22-Jul-2014 22:02:00 UTC] PHP Notice:  Undefined index: character_set in /public_html/forum/Sources/Subs-Post.php on line 1234


I wrote a small function to capture a stack trace when the undefined index is encountered at line 1234 in Subs-Post.php. Here's what it captured:


stk_trace: Called from /public_html/forum/Sources/Subs-Post.php:1236
stk_trace   1. mimespecialchars() /public_html/forum/Sources/Subs-Post.php:689
stk_trace   2. sendmail() /public_html/forum/Sources/ScheduledTasks.php:1364
stk_trace   3. scheduled_birthdayemails() -:-
stk_trace   4. call_user_func() /public_html/forum/Sources/ScheduledTasks.php:125
stk_trace   5. AutoTask() /public_html/forum/index.php:85

stk_trace: Called from /public_html/forum/Sources/Subs-Post.php:1236
stk_trace   1. mimespecialchars() /public_html/forum/Sources/Subs-Post.php:690
stk_trace   2. sendmail() /public_html/forum/Sources/ScheduledTasks.php:1364
stk_trace   3. scheduled_birthdayemails() -:-
stk_trace   4. call_user_func() /public_html/forum/Sources/ScheduledTasks.php:125
stk_trace   5. AutoTask() /public_html/forum/index.php:85

stk_trace: Called from /public_html/forum/Sources/Subs-Post.php:1236
stk_trace   1. mimespecialchars() /public_html/forum/Sources/Subs-Post.php:742
stk_trace   2. sendmail() /public_html/forum/Sources/ScheduledTasks.php:1364
stk_trace   3. scheduled_birthdayemails() -:-
stk_trace   4. call_user_func() /public_html/forum/Sources/ScheduledTasks.php:125
stk_trace   5. AutoTask() /public_html/forum/index.php:85

stk_trace: Called from /public_html/forum/Sources/Subs-Post.php:1236
stk_trace   1. mimespecialchars() /public_html/forum/Sources/Subs-Post.php:746
stk_trace   2. sendmail() /public_html/forum/Sources/ScheduledTasks.php:1364
stk_trace   3. scheduled_birthdayemails() -:-
stk_trace   4. call_user_func() /public_html/forum/Sources/ScheduledTasks.php:125
stk_trace   5. AutoTask() /public_html/forum/index.php:85

hebron

I am also seeing this it seems, just noticed it today. I ran the birthday schedule manually to see if the same errors occurred, they did not. I have however written a scheduled task of my own that sends email, and that runs at the same time as the birthday task. So my errors might be related to that one, although no errors are given when I run it manually or on the previous automatic runs.

I'll do some digging when I get the time :) So far I am not sure how to reproduce it...

SMF 2.0.8 with Norwegian UTF8 language.

sah62

Quote from: hebron on August 01, 2014, 01:38:02 PMSo far I am not sure how to reproduce it...

It happens for me every time the scheduled "send birthday emails" task runs automatically.

sinnerman

#13
Same thing here with almost the same configuration:

SMF 2.0.8, dedicated server, centos, selinux permissive,...

scheduled tasks that has to do with email WORK if you call them with run now but DON'T WORK when they 're called automatically...

i reached this thread trying to finally find a solution why i didn't ever manage to get the "summary of posts awaiting approval" to work..
same thing there. if i call it with Run Now..it works. on auto no email is coming out..exact same problems with subs-post.php

sah62

This bug isn't bogus and hasn't been fixed. This topic should probably be moved up to the "Bug Reports" board or re-posted there.

Kindred

Fixed in 2.1. It probably will not be addressed in 2.0.x
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

sah62

Quote from: Kindred on September 29, 2014, 06:31:59 AM
Fixed in 2.1. It probably will not be addressed in 2.0.x

Thanks for confirming the fix. Looking forward to 2.1, and no, I won't ask for a release date... ;)

Pyrhel

Quote from: Kindred on September 29, 2014, 06:31:59 AM
Fixed in 2.1. It probably will not be addressed in 2.0.x
I know it's 3 years old topic, I'm sorry, but wanted to share that I also have the exact same problem with version 2.0.14.
I recently enabled birthday emails and those undefined index notices (server, character_set, utf8) appeared in the error_log.

Steve

Please start a new topic with a description of your problem in the appropriate support board.
DO NOT pm me for support!

Irisado

As Steve says, you're welcome to open a topic in the 2.0.x Support board for specific help with your forum.

The bug/issue is, however, not going to be addressed in 2.0.X and has already been addressed in 2.1, as Kindred said, so this old topic is now locked.
Soñando con una playa donde brilla el sol, un arco iris ilumina el cielo, y el mar espejea iridescentemente

Advertisement: