You are hereForums / JDF Generally / Common JDF Questions / Does anyone succesfully made a JMF HTTP script in PHP?
Does anyone succesfully made a JMF HTTP script in PHP?
Hi,
I´m building a MIS system to interact with esko backtage. I´ve managed to make connection and send JMF with Alces.
Today I use hotfolders for JDF sending but as it only checks the hotfolder every 1 minute it is very timeconsuming.
But now I want to make my PHP script to send the JMF/JDF. Has anyone sucessfully done this or has any tips.
I´m trying to do it using cURL and POST but dont seem to get any response from the server.
I can´t find any information about the HTTP connection on cip4.
Please help me
/Pontus
Hi Pontus,
I've done a service in PHP which sends and receives JMF without any problems.
Can you tell me what you've done so far and where exactly your problem is?
Regards,
Albert van Peppen
Hi Albert
The problem is that I have no idea how to communicate over HTTP with JMF. I´m trying to do it with cURL.
Like this:
function createJMF()
{
$eskoJMF="http://rstbs1:4411/JDFP/JMF";
$urlJDF="http://rstintranet/php/jmfHF/TESTINGET.jdf";
$xml1='
<JMF xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.CIP4.org/JDFSchema_1_1" SenderID="Alces"
TimeStamp="2004-08-30T17:23:00+01:00" Version="1.2">
<Command ID="C1" Type="OpenQueue" xsi:type="CommandOpenQueue" />
</JMF>';
// init curl handle
$ch = curl_init($eskoJMF);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); // follow redirects recursively
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml1);
// perform post
echo $pnp_result_page = curl_exec($ch);
curl_close ($ch);
}
createJMF();This example is just a test to get the connection working. But I cant seem to get a response from the server whatever I try.
Regards
/Pontus Axelsson
Ok, I've tried to put a sample together (our PHP apps use a set of classes which handles everything, but it should end up like this :) )
<?php
//
// Sample application sending JMF to a JMF handling service
//
// For our JDF stuff this must be turned off! (Should be turned off in the PHP.INI but now we know for sure)
set_magic_quotes_runtime(0);
// HTTP result status to caller
$lResultStatus = HTTP_STATUS_OK; // HTTP_STATUS_OK: Assume all is OK
$strResultStatusString = 'OK';
$strContentType = 'application/vnd.cip4-jmf+xml';
// Build XML data containing the JMF
$strXML = '<?xml version="1.0" encoding="UTF-8" ?>'."\n".
'<JMF xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
' xmlns="http://www.CIP4.org/JDFSchema_1_1" SenderID="Alces"'.
' TimeStamp="2004-08-30T17:23:00+01:00" Version="1.2">'.
' <Command ID="C1" Type="OpenQueue" xsi:type="CommandOpenQueue" />'.
'</JMF>'."\n";
$strURL = 'http://jmfserver/jmfservice';
$http_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
$http_server_referer = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : '';
// Set data
if (!empty($http_host)) {
$arrHeaders['Host'] = htmlentities($http_host, ENT_QUOTES, "ISO-8859-15");
}
if (!empty($http_server_referer)) {
$arrHeaders['Referer'] = $http_server_referer;
}
$arrHeaders['Connection'] = 'Close'."\n"; // Keep-Alive if you want to do more communication like taking results :)
$arrHeaders['Content-Type'] = $strContentType."\n";
$arrHeaders['Content-Length'] = strval(strlen($strXML))."\n";
$arrHeaders['Expect'] = '';
$arrHeaders['Accept'] = '';
// Add the MIME stuff etc in this senddata as well
$strSendData = $strXML;
// HttpRequest
try {
$cReq = new HttpRequest($strURL, HttpRequest::METH_POST, Array("useragent" => "MyJMFProvider 1.0",
"referer" => $http_server_referer,
"headers" => $arrHeaders));
$cReq->setRawPostData($strSendData);
$res = $cReq->send();
// Get HTTP response code (should be 0 = OK)
$lHttpResult = $res->getResponseCode();
// Get response message (Most likely 'OK')
$strResponseMessage = $cReq->getResponseMessage();
// Do some result checking here
// ....
}
catch (HttpException $ex) {
echo 'Send HTTP request exception: '.$ex;
die();
}
// Flush caches
flush();
?>
It might not work directly, but the basics are clear I assume.
Regards,
Albert van Peppen
Hi Albert,
Thanks, I will give it a try right away.
Whatever I try I get a 500 error. I got a error installing pecl on linux. Seems to be a bug in pecl.
curl works fine on other urls. But it seems I cant get any response from the server. Updated the curl with your script:
// $url="http://rstintranet/php/test.php";
$url="http://rstbs1:4411/JDFP/JMF";
$urlJDF="http://rstintranet/php/jmfHF/TESTINGET.jdf";
$strContentType = 'application/vnd.cip4-jmf+xml';
//$strContentType = "application/x-www-form-urlencoded"; //text/html; charset=utf-8 //application/x-www-form-urlencoded;
$strXML = '<?xml version="1.0" encoding="UTF-8"?><JMF xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.CIP4.org/JDFSchema_1_1" SenderID="Alces" TimeStamp="2004-08-30T17:23:00+01:00" Version="1.2"><Command ID="C1" Type="OpenQueue" xsi:type="CommandOpenQueue" /></JMF>';
// init curl handle
$ch = curl_init();
$urldata = parse_url($url);
// Ensure we have the query too, if there is any...
$urldata['path'] .= "?".$urldata['query'];
// Header vars
$host="Host: ".$urldata['host'];
$referer="Referer: rstintranet";
$connection="Connection: 'Keep-alive: 300'";
$contentType="Content-Type: ".$strContentType;
$contentLength="Content-Length: ".strval(strlen($strXML));
$expect="Expect: ";
$accept="Accept: ";
$headers = array($host, $referer, $connection, $contentType, $contentLength, $expect, $accept);
curl_setopt($ch, CURLOPT_INTERFACE, "192.168.1.93");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, @$strXML);
// perform post
$result= curl_exec($ch);
curl_close ($ch);
echo ($result);
Sorry but I don't now about Curl.
I've tried to install it on my Windows machine but PHP keeps reporting it can't find the php_curl.dll.
So I can't help you with that right now..
But what I saw in other examples curl_setopt($ch, CURLOPT_POSTFIELDS, $strXML); (without the @) should work..
The $strXML is rawdata so in princople it should not be put in the postfields; but then again, what do I know about Curl ;)
Again, check the message in your php logfile and you might check the http server logs on the machine to which you send your jmf.
Is your message arriving there? Is it complete (eg. has it everything in it you send to it)
Albert
Can you tell us what/how you did it?
(So aybody else who needs it can find it on the web :) )
Albert
Finnaly got it working, the problem was cross servers. I had to fool the HTTP that it was from the same server: "curl_setopt($ch, CURLOPT_INTERFACE, "xxx.xxx.xxx.93")".
Here is the PHP script that I call with AJAX.
<?php
$strJMF=$_POST['strJMF'];
function sendit($strJMF)
{
$url="http://xxx.xxx.xxx.91:4411/JDFP/JMF";
$strContentType = 'application/vnd.cip4-jmf+xml';
// init curl handle
$ch = curl_init();
$urldata = parse_url($url);
$host="Host: ".$urldata['host'];
$referer="Referer: rstintranet";
$connection="Connection: keep-alive, Keep-alive: 300'";
$contentType="Content-Type: ".$strContentType;
$contentLength="Content-Length: ".strval(strlen($strJMF));
$expect="Expect: ";
$accept="Accept: ";
$headers = array($host, $referer, $contentType, $contentLength);
curl_setopt($ch, CURLOPT_INTERFACE, "xxx.xxx.xxx.93");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strJMF);
// perform post
$result= curl_exec($ch);
curl_close ($ch);
return $result;
}
$result=sendit($strJMF);
echo $result;
?>
Hi Pontus,
you have to put the message into a HTTP Stream for transmission. I'm not very familiar with PHP but I haven't find any part in your sample code which sould shows you are using a HTTP Stream.
(c)
Stefan


