-2

Can anyone provide me the code to execute the curl command given below using drupal :

$ curl -k -X POST https://openshift.redhat.com/broker/rest/domains/[Domain_ID]/applications --user "[UserName]:[Password]" --data "name=[AppName]&cartridge=php-5.3&scale=false"

Thanks

Sagar Awasthi
  • 538
  • 5
  • 10
  • You could run this as a command, using `exec` or similar. In general, when asking questions if you can outline what you have tried, it helps guide answers to something that will be most useful to you. – halfer Apr 07 '14 at 11:05
  • ok thanks, but i just try exec but the page d'ont respond ;) – The Great Gatsby Apr 07 '14 at 11:23
  • OK, so you'll need to debug it. How big do you expect the fetch to be? If it will take more than a few seconds, it would be best to do it outside of a web request, maybe on a cron. – halfer Apr 07 '14 at 11:46

2 Answers2

0

Take a look to the PHP cURL module https://php.net/curl

Example Using PHP's cURL module to fetch the example.com homepage

<?php
$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

You can also use exec to execute cURL commands https://php.net/manual/en/function.exec.php

Companjo
  • 1,789
  • 18
  • 24
0

1. Use Exec to execute your original statemant

You can use php exec to execute arbitrary commandline functions.

http://www.php.net/manual/de/function.exec.php

2. You can try to use the php curl function if it fits your need i would use that.

http://de1.php.net/manual/de/function.curl-init.php

As this post describes What is cURL in PHP? you need to install libcurl.

Example:

php> $ch = curl_init();

php> curl_setopt($ch, CURLOPT_URL, 'http://i.imgur.com/wtQ6yZR.gif');

php> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

php> $contents = curl_exec($ch);

php> echo $contents;
Community
  • 1
  • 1
Dukeatcoding
  • 1,363
  • 2
  • 20
  • 34