Advertisement:

Author Topic: PHP Undefined Index Notices in Subs-Post.php  (Read 15594 times)

Offline sah62

  • Semi-Newbie
  • *
  • Posts: 67
PHP Undefined Index Notices in Subs-Post.php
« on: January 25, 2014, 09:54:52 PM »
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:

Code: [Select]
[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

Code: [Select]
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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,050
    • Arantor on GitHub
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #1 on: January 25, 2014, 10:16:32 PM »
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...
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline sah62

  • Semi-Newbie
  • *
  • Posts: 67
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #2 on: January 26, 2014, 05:10:42 PM »
So it's almost certainly more specific to your installation...

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

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,050
    • Arantor on GitHub
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #3 on: January 26, 2014, 10:28:28 PM »
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. :(
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME


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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,050
    • Arantor on GitHub
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #5 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), 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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #6 on: January 30, 2014, 11:06:38 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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,050
    • Arantor on GitHub
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #7 on: January 30, 2014, 11:13:12 AM »
The only place index.php?scheduled seems to be called is:

Code: [Select]
$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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #8 on: January 30, 2014, 03:12:15 PM »
Code: [Select]
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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,050
    • Arantor on GitHub
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #9 on: January 30, 2014, 09:44:09 PM »
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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline sah62

  • Semi-Newbie
  • *
  • Posts: 67
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #10 on: July 23, 2014, 01:30:09 PM »
I'm still seeing this issue in 2.0.8. Any diagnostic help would be appreciated.

Code: [Select]
[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:

Code: [Select]
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
« Last Edit: July 23, 2014, 06:12:18 PM by sah62 »

Offline hebron

  • Semi-Newbie
  • *
  • Posts: 31
  • Gender: Male
    • thomasjsn on GitHub
    • @thomas_jsn on Twitter
    • uCtrl Development
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #11 on: August 01, 2014, 01:38:02 PM »
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.
My digital playground; uCtrl.io, electronics, microcontrollers and computer stuff.

Offline sah62

  • Semi-Newbie
  • *
  • Posts: 67
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #12 on: August 03, 2014, 01:42:12 PM »
So far I am not sure how to reproduce it...

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

Offline sinnerman

  • Semi-Newbie
  • *
  • Posts: 16
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #13 on: August 23, 2014, 01:50:51 PM »
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
« Last Edit: August 23, 2014, 02:27:52 PM by sinnerman »

Offline sah62

  • Semi-Newbie
  • *
  • Posts: 67
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #14 on: September 29, 2014, 06:29:50 AM »
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.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 55,119
  • Gender: Male
    • Kindred-999 on GitHub
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #15 on: September 29, 2014, 06:31:59 AM »
Fixed in 2.1. It probably will not be addressed in 2.0.x
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline sah62

  • Semi-Newbie
  • *
  • Posts: 67
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #16 on: September 29, 2014, 06:45:24 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... ;)

Offline Pyrhel

  • Semi-Newbie
  • *
  • Posts: 80
    • FordBG.com
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #17 on: August 31, 2017, 02:59:21 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.

Offline Steve

  • Support Specialist
  • SMF Hero
  • *
  • Posts: 3,935
  • Gender: Male
  • I have not yet begun to procrastinate.
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #18 on: August 31, 2017, 12:28:01 PM »
Please start a new topic with a description of your problem in the appropriate support board.
Please do not PM me for support.

Online Irisado

  • Doc Coordinator
  • SMF Hero
  • *
  • Posts: 9,009
  • Soñando debajo del arco iris
Re: PHP Undefined Index Notices in Subs-Post.php
« Reply #19 on: August 31, 2017, 12:36:09 PM »
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