Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print something in PHP built-in web server

In python built-in web server when use print in function, it prints result in terminal ...

for example:

Django version 1.3.4, using settings 'parsicore.settings' Development server is running at http://0.0.0.0:8000/ Using the Werkzeug debugger (http://werkzeug.pocoo.org/) Quit the server with CONTROL-C.   127.0.0.1 - - [16/Jan/2013 02:02:08] "GET / HTTP/1.1" 200 - hello ... print 1 2 3  

How can I print something like this in PHP built-in web server?

for example I want print $_POST in terminal. I use php -S 127.0.0.1:3000 for run PHP built-in web server.

like image 529
Mohammad Efazati Avatar asked Jan 16 '13 08:01

Mohammad Efazati


People also ask

Can I print on PHP?

With PHP, there are two basic ways to get output: echo and print . In this tutorial we use echo or print in almost every example.

What is a PHP web server?

PHP server is a collection of fundamental tools that make it easy to host at local servers so you can develop or built Web Apps at your computer. If you're are doing development on web application, having a PHP server is perfect way, the most perfect way to start.

How do I run a PHP web application locally?

If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

How get all data request in PHP?

You can use the PHP command apache_request_headers() to get the request headers and apache_response_headers() to get the current response headers. Note that response can be changed later in the PHP script as long as content has not been served.


2 Answers

Just pipe your data to error_log():

error_log(print_r($_REQUEST, true)); 

like image 79
acidjazz Avatar answered Oct 05 '22 20:10

acidjazz


The development web server built in to PHP 5.4+ does not work in the way you want. That is, it's not a PHP process, and you can't have it run code for you.

It's designed to serve PHP applications and content from the specified directory. The output of the server process is the access log. You can write to the log using the error_log function, with a value of 4 as the message_type. So, in theory, you could do something like

ob_start(); var_dump($_POST); error_log(ob_get_clean(), 4); 

It sounds like you're trying to perform some debugging. You should be using real debugging tools instead of cobbling something together.

like image 35
Charles Avatar answered Oct 05 '22 19:10

Charles