Jump to content

HTTP POST.......


unplugged_web
 Share

Recommended Posts

It looks like the TM-T88IV is a specific printer from Epson, is that what you're using? Are the printers connected to the VOIP system?
I'm not sure if it's an Epson printer, but am pretty sure it is. The VOIP system isn't connected to the printer though. I need to send the results of the VOIP system to the printer and was told the best way of doing this was via HTTP POST
Link to comment
Share on other sites

What exactly do you mean by "use HTTP POST to send the results from a VOIP system to a printer"?If you're able to break this down a little, I think you'll find the answer yourself. In particular, how does the VOIP system send it's results? HTTP POST or another method? Whatever it is, you'll need to look it up, and most likely, adjust it to somehow.Here's an idea (assuming the VOIP system sends the results as HTTP POST), connect the printer to a computer. On that computer, install a web server (Apache) and PHP. Also install the printer extension. Create a PHP file that will receive the results. Make it connect to the printer, printing whatever it received from the VOIP system.

Link to comment
Share on other sites

What exactly do you mean by "use HTTP POST to send the results from a VOIP system to a printer"?If you're able to break this down a little, I think you'll find the answer yourself. In particular, how does the VOIP system send it's results? HTTP POST or another method? Whatever it is, you'll need to look it up, and most likely, adjust it to somehow.Here's an idea (assuming the VOIP system sends the results as HTTP POST), connect the printer to a computer. On that computer, install a web server (Apache) and PHP. Also install the printer extension. Create a PHP file that will receive the results. Make it connect to the printer, printing whatever it received from the VOIP system.
Okay, I'll find out how the VOIP sends the results. I guess the PHP file that receives the results then prints them would be something like
<?php$voipFile = 'whatever.com';$printFile = getcwd() . '/results.txt';if (!is_bool(file_get_contents('whatever.com'))) {		file_put_contents($printFile,());		print($printFile, ());	}		?>

Link to comment
Share on other sites

I forgot to ask... does the VOIP system actually send anything, or is it just giving to anyone when asked (and how does it provide the information when asked? HTTP?).Your sample code would (almost) work if the VOIP system has an HTTP server that reponds to queries. If that is the case, you'll have to make PHP ask it periodically ("cron job" style), and print everything new in the response.If the VOIP system can periodically send a file (via FTP or SMB perhaps) to a computer on the local network, you'll have to periodically invoke the PHP script and print our all newly received files.If the VOIP system sends files out with FTP, then you must install an FTP server on that computer. This FTP may be adjusted to start the PHP file upon receiving a file (I think WarFTP can be made to do that).It's the easiest if the VOIP system can send an HTTP request. In that case, your PHP script will simply receive what is new and print it directly.

Link to comment
Share on other sites

I forgot to ask... does the VOIP system actually send anything, or is it just giving to anyone when asked (and how does it provide the information when asked? HTTP?).Your sample code would (almost) work if the VOIP system has an HTTP server that reponds to queries. If that is the case, you'll have to make PHP ask it periodically ("cron job" style), and print everything new in the response.If the VOIP system can periodically send a file (via FTP or SMB perhaps) to a computer on the local network, you'll have to periodically invoke the PHP script and print our all newly received files.If the VOIP system sends files out with FTP, then you must install an FTP server on that computer. This FTP may be adjusted to start the PHP file upon receiving a file (I think WarFTP can be made to do that).It's the easiest if the VOIP system can send an HTTP request. In that case, your PHP script will simply receive what is new and print it directly.
Thanks, I've asked the people who've got the system if the VOIP sends information or how it works. As soon as I her back from them I'll post more details about it
Link to comment
Share on other sites

Thanks, I've asked the people who've got the system if the VOIP sends information or how it works. As soon as I her back from them I'll post more details about it
Okay, I've just got an email from the people who are dealing with the VIOP system. They've said that their service will collect customer orders on a phone call, which they'll then sending to a URL specified by us as a simple HTTP post. So I guess I need to get the results from that and then get the printer to print them?
Link to comment
Share on other sites

I've just found out that the printers are local serial printers hanging off the RMServer PC's and I've been told that this is the main file server.Does that mean that I can use

<?php$voipFile = 'whatever.com';$printFile = getcwd() . '/results.txt';if (!is_bool(file_get_contents('whatever.com'))) {		file_put_contents($printFile,());		print($printFile, ());	}		?>

to get the results and then send them direct to the printer?

Link to comment
Share on other sites

In order to even run PHP at all, the server that the printers are connected to needs to have web server software installed plus PHP installed. Can you configure the VOIP system to say where it submits the data? You would enter the server that you set up and give it the address to a PHP page that will check $_POST and format the data to send it to the printer. Printing isn't as straightforward as you might imagine though, the PHP printer package only works on Windows servers and requires PECL to be installed, and when you format the data you need to send certain printer control characters. You should be able to find information about those in documentation for the printer from Epson. There will probably also be some generic examples online if you search for PHP printer.Also, the print command doesn't send data to a printer, it prints data to the screen. I'm not sure what the rest of that code is doing with the check on file_get_contents and then the call to file_put_contents, but it's going to require a lot more code then a few lines.

Link to comment
Share on other sites

The least code you'll need (assuming you just want to print the text as received, "no questions asked" so to speak) you'll need:

<?php$handle = printer_open();printer_write($handle, print_r($_POST, true));printer_close($handle);?>

(sample is almost directly taken from the printer extension's manual)On Windows, PECL extensions are just DLLs (in your case, it should be the last of this bunch of DLLs) that you have to place in your extension_dir and enable in php.ini.And before you try the above, yes, it WILL give an error. Remember, as justsomeguy said already, the computer to which the printer is connected to MUST have a web server and PHP running. In addition, this extension MUST be installed. If you miss any of theese steps, only an error will occur, and the printer won't do anything.

Link to comment
Share on other sites

That won't actually work, print_r doesn't return anything, it only prints. You would need to use output buffering to capture the output from print_r and then send that to the printer.
Have you forgotten print_r's second argument?
Link to comment
Share on other sites

Have you forgotten print_r's second argument?
I just want to make sure I've got everything right if that's okay. I need to make sure the computer that the printer is connected to is a web server running php and I need to I need to install and enable the dll. Then the php file will print the results coming from the HTTP POST? And I guess I need to do that with every store that will receive the HTTP POST?One question though, how will the file know when to print, will it automatically print or will I need to do something to get it to check?Thanks
Link to comment
Share on other sites

Have you forgotten print_r's second argument?
Well, yeah...You can install a web server on a file server, there's nothing special about a fileserver really software-wise, it's just a computer that sits there with a lot of storage. Might as well slap a web server on it!The main thing to figure out is how the post submission happens. Is it automatic where you have your server set up, and the VOIP system just periodically sends a post request to the server to print? Is it any more complex than that?
Link to comment
Share on other sites

Well, yeah...You can install a web server on a file server, there's nothing special about a fileserver really software-wise, it's just a computer that sits there with a lot of storage. Might as well slap a web server on it!The main thing to figure out is how the post submission happens. Is it automatic where you have your server set up, and the VOIP system just periodically sends a post request to the server to print? Is it any more complex than that?
The VOIP system is used for people to place orders and the that is sent straight to a URL (http://ip address). After the request is sent it then needs to be sent to the store to be printed.How do I make a file server a web server though? What do I need to install and can I do it remotely? Also is it difficult?Thanks for helping me.
Link to comment
Share on other sites

One question though, how will the file know when to print, will it automatically print or will I need to do something to get it to check?
Since the VOIP system sends the HTTP request when printing needs to be done, the PHP file doesn't need to know when to print. It will print as soon as it's executed. It's up to the VOIP system to execute it at the right time.
How do I make a file server a web server though? What do I need to install and can I do it remotely? Also is it difficult?
We are talking about Windows computer(s), right? After all, the PHP printer extension won't work on Linux based systems (or anything that is not Windows). If so, here's a detailed tutorial. The printer extension is installed in the same fashion you install the php_mysql.dll or php_xsl.dll files (described in a later point of the tutorial).Feel free to skip the MySQL part. It's not needed for your case. Just do everything up to "Test PHP5".
Link to comment
Share on other sites

Since the VOIP system sends the HTTP request when printing needs to be done, the PHP file doesn't need to know when to print. It will print as soon as it's executed. It's up to the VOIP system to execute it at the right time.We are talking about Windows computer(s), right? After all, the PHP printer extension won't work on Linux based systems (or anything that is not Windows). If so, here's a detailed tutorial. The printer extension is installed in the same fashion you install the php_mysql.dll or php_xsl.dll files (described in a later point of the tutorial).Feel free to skip the MySQL part. It's not needed for your case. Just do everything up to "Test PHP5".
Thank you. I'll go through the tutorial and install it.
Link to comment
Share on other sites

  • 2 weeks later...
Am I okay just uploading it to the server or does it need to be installed in a root file?
You mean the Printer extension? It goes in the extensions folder, ask the people setting it up or phpinfo() for where it is. Also, don't forget to enable it in php.ini.
Link to comment
Share on other sites

Okay the server is now being set up as a web server for me, but I didn't think to ask where the file should be. Am I okay just uploading it to the server or does it need to be installed in a root file?Thanks
Which file? The extension? It needs to be in the "ext" directory in PHP. That is, if you have PHP installed in
D:\PHP\

the file must be placed in

D:\PHP\ext\

Then, in php.ini, make sure the extension_dir is pointing to that directory. In other words, find

extension_dir =

and adjust the whole line so that is says:

extension_dir = "D:\PHP\ext"

Then, add the following line in php.ini:

extension=php_printer.dll

Restart Apache. The printer extension should now be available.

Link to comment
Share on other sites

Which file? The extension? It needs to be in the "ext" directory in PHP. That is, if you have PHP installed in
D:\PHP\

the file must be placed in

D:\PHP\ext\

Then, in php.ini, make sure the extension_dir is pointing to that directory. In other words, find

extension_dir =

and adjust the whole line so that is says:

extension_dir = "D:\PHP\ext"

Then, add the following line in php.ini:

extension=php_printer.dll

Restart Apache. The printer extension should now be available.

Thank you, but what about the:
<?php$handle = printer_open();printer_write($handle, print_r($_POST, true));printer_close($handle);?>

bit?

Link to comment
Share on other sites

Thank you, but what about the:
<?php$handle = printer_open();printer_write($handle, print_r($_POST, true));printer_close($handle);?>

bit?

Well, now that the printer extension is available, if the VOIP system makes a request to that PHP file, the printer should print the contents of the POST array. It will look ugly, but at least you'll make sure it works OK and that you can really see all the information.If you want to test out the printer extension without the VOIP system, try something even simpler, like say:
<?php$handle = printer_open();printer_write($handle, "This is a printing test");printer_close($handle);echo "Printer should start printing...";?>

Open this in your browser. The printer should be printing a document saying "This is a printing test", and on screen, you'd see "Printer should start printing...".

Link to comment
Share on other sites

Well, now that the printer extension is available, if the VOIP system makes a request to that PHP file, the printer should print the contents of the POST array. It will look ugly, but at least you'll make sure it works OK and that you can really see all the information.If you want to test out the printer extension without the VOIP system, try something even simpler, like say:
<?php$handle = printer_open();printer_write($handle, "This is a printing test");printer_close($handle);echo "Printer should start printing...";?>

Open this in your browser. The printer should be printing a document saying "This is a printing test", and on screen, you'd see "Printer should start printing...".

Brilliant, thank you
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...