Link to home
Start Free TrialLog in
Avatar of darroosh
darroosh

asked on

Send a file from my server to a page on another server to be processed and return me an xml reply..

Hi,

My exact case :

When  a site user tries to register , he uploads a word file ( his CV).
Then  this word  file is processed to extract some data from it ..

This is working fine till now.
But what I want , Is , after he click submit the  registration form, his  data sent to the server will have some processing and some data to be inserted in the DB , and to open a connection with another  server to send the uploaded file to it , to be processed on the second server and then send me the reply as XML file .. to be processed again on  my original file..

What  are the suggestions for doing that ?
Reason:  My original server is running on Linux , And I the file processing to be on windows to be able to use the COM class which is only available on the windows version of PHP.
And I don't prefer to transfer my site to a windows hosting due to security reasons.

Any help?
Avatar of edster9999
edster9999
Flag of Ireland image

First of all - think about this the other way round.   Keep the file in linux.  Why would you be going to a windows server ??? Anything Windows can do, Linux can do better and faster (well almost anything).
There are a lot of PHP libraries and plugins to read MS files and talk to databases - try one of those before you jump into windows.

If you do need to move it to another server - either a linux one or a windows one, then you need to copy the file to that box (unless they have access to a shared file area. Once you have the file over (either on a share or by passing it to a web page as submitted form data) then you can reference the file by its name.
Avatar of darroosh
darroosh

ASKER

Please read the first line of this page:
http://www.php.net/manual/en/com.requirements.php

COM functions are only available for the Windows version of PHP.
And this is the reason I need windows server...


About the PHP libraries you are talking about , I tried most of the free ones with a result not 100% matching what I need ..   always I face some problem..So I decided to create my own library. I already created it , and it's working fine with my requirements giving me about 100 % of my job ( using COM class was the best results ) ..

About  the second half of your reply, I didn't get it .. I want the form data to be sent to a page on my original server to be processed there  , then this page should open a connection with another page on another server sending it the file to be processed there and wait the response which will be XML file..
You might want to read up on client/server protocols.  What you're designing is likely to look like a camel in a horse race.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

Executive summary: You do not "send" files to another machine.  The other machine must request the file.  You have some freedom to get around this rule of HTTP if you go outside of the HTTP protocols. For example, you might be able to open FTP connections between the machines.  This is a research project, so plan accordingly as you budget your time.

This question from last month is still open.  Have you gotten COM working now?
Your article is excellent, Thanks for it, I read some of it and I will continue to read the rest.

Before reading your reply, I was able to do what I want using cURL in PHP..
This page helped me :
http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/

What is your opinion in that ?

But I need explanation why you say:
What you're designing is likely to look like a camel in a horse race.

About my COM problem, Unfortunately , It have not been solved! I just  changed the server and I'm still trying to check it in a new one.
Thanks.  The use of cURL to make a POST request seems feasible, but I think if I wanted to use COM, I would just put the entire application on a Windows server.  I don't think Windows is inherently any less secure.  Having two machines feels more complicated to me.

As I think about this problem with two machines, it seems to take the shape of a web service.  The Windows machine might expose an API that is available via a POST request.

Linux machine:
1. base64_encode() the Word document
2. POST the encoded Word document to the Windows machine
3. sleep() for a moment to allow Windows machine to work
4. Read the response from Windows machine

Windows machine:
1. base64_decode() the document, turning it back into Word document
2. Do processing as needed with COM
3. Write the response as if it were browser output

I believe this is feasible with either cURL or fsockopen().  I think I would try to avoid sending a file, and just send the contents of the file as a character string.
Thank you for your help ..


Yes it looks  like a web service , that's what i really thought about..
Because my case is that  I need a windows component , But I prefer linux stability and  security over  windows . So I tried that to get  both benefits.

Anyway,
I tried my real code and had a small test.
File uploaded  from my local machine to the linux server , the linux server sent  the file  to the windows server, the windows server just saves the file and return some data about it ( type, ext , size)..

The overall time spent for that : 0.00876092910767 .
Time will be  spent in the  windows  processing is n't an addition to the script execution  time, because it's a must  to be  processed either on linux or on windows..


About avoiding to send the file and send its contents . that's exactly what I can't do , Because I send the file to the windows machine to get its contents using the windows COM..  On the linux machine(missing COM) , when I try to get  the file contents, sometimes it's extracted with accuracy less than 100%, and If I could make it 100%, so the windows machine is useless !


Conclusion, What is your opinion, does my solution to make it like web service make sense ???
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Does HTTPS adds any time for transferring data ?

Also how to do that ?
Should buy an SSL certificate on the windows machine to be able to call it using HTTPS ?
Does HTTPS adds any time for transferring data ?
Yes, it is noticeably slower on very large documents, but typically the delay is not enough to worry about.  Talk to your hosting company about how to set this up.  There is usually a modest cost.

Thanks for the points and thanks for using EE, ~Ray
Sorry, but another questions:

You said that I must base64_encode my file before  sending it to the server ..
Why this is important ?
And what if I didn't encode it ..
And how to encode it  ?

Regards
Bas64_Encode() and Base64_Decode() work together to enable you to send binary data across interfaces that are not "8-bit clean," such as mail bodies or SQL connections.  Certain characters have meaning to these unclean interfaces, and binary data such as might be generated in external documents could contain something like a "stop" character.  Check the man page links for details.
In our case , does the two machines are 8-bit clean or not ?