Page 1 of 1

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

PostPosted: 20. July 2012 00:17
by malaugh
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?

Re: Can I write to the console in PHP?

PostPosted: 20. July 2012 00:31
by JonB
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)

Re: Can I write to the console in PHP?

PostPosted: 20. July 2012 01:00
by JonB
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)

Re: Can I write to the console in PHP?

PostPosted: 20. July 2012 04:38
by malaugh
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?

Re: Can I write to the console in PHP?

PostPosted: 20. July 2012 04:44
by hackattack142
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.

Re: Can I write to the console in PHP?

PostPosted: 20. July 2012 14:39
by Altrea
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

Re: Can I write to the console in PHP?

PostPosted: 20. July 2012 15:29
by malaugh
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.

Re: Can I write to the console in PHP?

PostPosted: 20. July 2012 15:55
by Altrea
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 :)