Can I write to the console in PHP? [Answered]

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Can I write to the console in PHP? [Answered]

Postby malaugh » 20. July 2012 00:17

Sorry if this is obvious, I'm a newbie. I am using Xampp USB lite, which starts a console window when you execute xampp_start. Is there a way to write to the console window with PHP? I would like to use this to debug my code. I tried print and echo but they print on the web page. I also tried error_log, but that did not print anywhere.

Is there a way to do this? Any better way to log values to debug my code?
malaugh
 
Posts: 3
Joined: 20. July 2012 00:06
Operating System: windows 7

Re: Can I write to the console in PHP?

Postby JonB » 20. July 2012 00:31

Take a look at this post - its the same kind of issue.
viewtopic.php?f=16&t=51020&p=196430#p196430

I have always used the full versions on my USB sticks

Good Luck

8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Can I write to the console in PHP?

Postby JonB » 20. July 2012 01:00

I have sent a note to 'those who matter' on these two posts as I think they reflect the same design choices. It may well be that some things just won't work with relative paths and the developers knew that when they decided on the 'design feature set'. (my working theory)

So your concerns have been heard. There may be nothing to be done with the current version other than hand configuring or running the full version.

Besides the above I will do some research on my own. However, as I am a full time developer and an Admin/Leader on another Open Source project, I cannot say when I will be able to do 'my thing' on this topic.

Good Luck on our projects.
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Can I write to the console in PHP?

Postby malaugh » 20. July 2012 04:38

Jonb - Sorry to ask more dumb questions. I read the link you posted, it talks about installing pear, and I am having trouble understanding where that fits in the picture. I have never used the full version of xampp. what debug capability would it give me that is missing in the lite version? Is there some kind of console I can write to?
malaugh
 
Posts: 3
Joined: 20. July 2012 00:06
Operating System: windows 7

Re: Can I write to the console in PHP?

Postby hackattack142 » 20. July 2012 04:44

I am not sure I understand this (Disclaimer: I am not a PHP developer). You will not get PHP output on the console unless you are running your script from the console manually. PHP does have an API to write to files (such as this: http://php.net/manual/en/function.file-put-contents.php) if that is your intention. The Console window that appears via xampp_start is only a way to control the XAMPP components and will not display the contents of your website. You can get browser extensions like FireBug in combination with FirePHP (http://getfirebug.com/ also see here http://sixrevisions.com/web-development ... h-firephp/) or other similar extensions for other browsers to debug scripts inside the browser. You also have the option of using an IDE (such as Eclipse) to do debugging. There are also debugging extensions like xdebug (http://xdebug.org/index.php). There are many ways to do debugging just have to see what works best for you.
XAMPP Control Panel Developer
Latest CP: viewtopic.php?f=16&t=48932
hackattack142
 
Posts: 703
Joined: 20. May 2011 23:29
Operating System: Windows 7 Ultimate SP1 64-Bit

Re: Can I write to the console in PHP?

Postby Altrea » 20. July 2012 14:39

I totally agree with hackattacks post.

The only "common" way to get php outputs in the command line is to use the php interpreter directly via command line (like demonstrated by the setup_xampp.bat script).
But you can't output something in a foreign command line window as wished (as far as i know - never needed something like this).

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Can I write to the console in PHP?

Postby malaugh » 20. July 2012 15:29

Thanks to everyone for their help. I started using file_put_contents in my code http://php.net/manual/en/function.file-put-contents.php, and tail for windows to view the file http://sourceforge.net/projects/tailforwin32/ this is working well, just need to work out a way of limiting the file size and turning logging on and off.

Thanks again to everyone for their help.
malaugh
 
Posts: 3
Joined: 20. July 2012 00:06
Operating System: windows 7

Re: Can I write to the console in PHP?

Postby Altrea » 20. July 2012 15:55

malaugh wrote:just need to work out a way of limiting the file size

You could use logrotate for this:
http://serverfault.com/questions/11892/ ... erver-2003

or this solution:
http://snippetsofcode.wordpress.com/201 ... g-support/

or simply google for other log rotation php solutions :)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8286
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 46 guests