3

Today I met a problem above:

[03-Nov-2017 19:29:02 Asia/Shanghai] PHP Fatal error: Call to undefined function header() in /www/xxxx/api/login.php on line 5

[03-Nov-2017 19:27:37 Asia/Shanghai] PHP Fatal error: Call to undefined function dirname() in /www/xxxx/index.php on line 9

...

I cannot find the reason and solution. anyone helps me, thanks.

add my code.

<?php
header('Content-type:text/html; charset=utf8');
include_once dirname(__FILE__). '/global.inc.php';

echo 'HELLO WORLD';

this problem happens sometimes and have last for one day, in my online website. what i can do is to reload each 1 hour.

anyone knows how to solve it??? THXTHX


UPDATE: Server Info added: Nginx Server, CentOS release 6.3. PHP Version 5.4.41

What confuse me most is that this problem happened suddenly on my online website with no changes published.

yip
  • 123
  • 1
  • 11
  • 1
    can you please attach some code! We'll try to solve it as fast as we can! –  Nov 03 '17 at 12:03
  • 1
    You need to show your code – B. Desai Nov 03 '17 at 12:04
  • first check this link . it might help you. https://stackoverflow.com/questions/7186926/fatal-error-call-to-undefined-function-phpinclude – prakash tank Nov 03 '17 at 12:04
  • post the code as well – Masivuye Cokile Nov 03 '17 at 12:05
  • it happens sometimes, and will be fine after I reload the php-fpm, and it happens about 40~50min again. – yip Nov 03 '17 at 12:08
  • @yip the code works fine on my side with no errors – Masivuye Cokile Nov 03 '17 at 12:09
  • @yip it is predefined functions of php and are always loaded when php is runned. Suggested option - remove php/server and reinstall. –  Nov 03 '17 at 12:12
  • thanks a lot. but nothing helps – yip Nov 03 '17 at 12:31
  • check this [link](https://bugs.php.net/bug.php?id=61503) – YouneL Nov 03 '17 at 12:37
  • @YouneL thx, but don't related to my problem – yip Nov 03 '17 at 12:51
  • What web server are you using? Nginx? Apache? What's the operating system? – Camilo Nov 06 '17 at 02:31
  • Do you have extensions installed? Like Xdebug for example – Camilo Nov 06 '17 at 02:36
  • @Camilo yes, with those extensions: dcode.so, eaccelerator.so, redis.so, xhprof.so – yip Nov 06 '17 at 02:39
  • I would try disabling all extensions, then enabling one by one until I find the one causing the error. Also, add your PHP version to your question. – Camilo Nov 06 '17 at 02:43
  • @Camilo thx to your suggestion, but it is hard to debug. Because the error I posted appears occasionally. – yip Nov 06 '17 at 02:49
  • it appears to be your hosting provider problems , you need to contact them – Neji Soltani Nov 06 '17 at 02:51
  • @SoltaniNeji We manage servers by ourself. – yip Nov 06 '17 at 02:54
  • hi, please do a php -m, php --version and put it in the answer (to check the modules and version exactlly ) – User123456 Nov 06 '17 at 03:04
  • It's almost sure that there appeared some "hidden" problems on your servers, which produced this unexpected behavior. They can be multiple, inclusive something that you've done and forgot. The essential sign about it is that these functions (header(), time(), etc) are part of the core imolementation of the PHP engine, and they don't work anymore. php.net says for the network functions (inclusive header() function): "_There is no installation needed to use these functions; they are part of the PHP core_"... –  Nov 06 '17 at 03:08
  • So, I suggest you to upgrade the PHP to version 7+. I'm convinced that you have this opportunity. Good luck. –  Nov 06 '17 at 03:09
  • @aendeerei : https://github.com/perusio/drupal-with-nginx/issues/55 – User123456 Nov 06 '17 at 03:15
  • @yip : could you have a look at the above linnk as well. also check the logs (tail -600f /var/log/httpd/error_log) – User123456 Nov 06 '17 at 03:15
  • still not works for me – yip Nov 06 '17 at 03:49
  • @yip : can you enable mod_php and disable PHP-FPM module and see your application is crashing ? – User123456 Nov 06 '17 at 04:55
  • What is your server specification in terms of RAM, CPU? Also how much CPU is usually free? Any chance your system got exposed to some malware recently? – Tarun Lalwani Nov 06 '17 at 11:30

1 Answers1

1

A really wild guess, but these errors could be deceiving you.

[03-Nov-2017 19:29:02 Asia/Shanghai] PHP Fatal error: Call to undefined function header() in /www/xxxx/api/login.php on line 5

[03-Nov-2017 19:27:37 Asia/Shanghai] PHP Fatal error: Call to undefined function dirname() in /www/xxxx/index.php on line 9

What if header() and dirname() contain a leading unicode character that is invisible or was somehow stripped from your log files? They might look like built-in PHP functions, but maybe your code contains special characters either in compiled form, or at runtime. In other words, header() might not be what you think it is. Even though it looks that way in the log.

I suggest a quick review of the following:

jaswrks
  • 1,255
  • 10
  • 13
  • 3
    for gods sake, don't use declare(encoding), juse use a sane editor that use utf8. it's **very difficult** to imagine an exception to this rule. – hanshenrik Nov 06 '17 at 11:15
  • Agree. And just wanted to add that I didn't mean to imply that it should be done that way. Just to check and be sure the existing file(s) do not have this, such they it would alter the anticipated behavior. – jaswrks Nov 06 '17 at 11:24