PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 15, 2022

[FIXED] $_SERVER['SERVER_NAME'] is not working with console application in Yii framework

 February 15, 2022     console-application, php, yii     No comments   

Issue

When i am trying to run my photoResizer command like this /var/www/myProject/proted/yiic photoResizer

i am getting this error.

PHP Error[8]: Undefined index: SERVER_NAME
in file /var/www/myProject/protected/components/UploadHandler.php at line 190
#0 /var/www/myProject/protected/components/UploadHandler.php(45):  
UploadHandler->get_full_url()
#1 /var/www/myProject/protected/commands/PhotoResizerCommand.php(37):   
UploadHandler->__construct()
#2 /var/www/myProject/framework/console/CConsoleCommandRunner.php(71):    
PhotoResizerCommand->run()
#3 /var/www/myProject/framework/console/CConsoleApplication.php(92): 
CConsoleCommandRunner->run()
#4 /var/www/myProject/framework/base/CApplication.php(180): 
CConsoleApplication->processRequest()
#5 /var/www/myProject/framework/yiic.php(33): CConsoleApplication->run()
#6 /var/www/myProject/protected/yiic.php(7): require_once()
#7 /var/www/myProject/protected/yiic(4): require_once()

I need to solve this problem or any alternative to run a php script via command line in yii framework.

Thanks.


Solution

Quite obviously there's no "server" when running an app from the command line, so you cannot use that variable for anything. Apparently UploadHandler is hard coded to expect to be executed in the context of a web request to handle files uploaded within the request (which, you know, makes sense). Since you're not in a web request context, it fails.



Answered By - deceze
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing