Wednesday, May 29, 2013

How to retrieve PHP's $_SESSION from a page called by cURL

Code for the page where you do cURL:
 <?php  
 $ch = curl_init();  
 curl_setopt($ch, CURLOPT_URL,"url of the page");   // The URL to fetch
 curl_setopt($ch, CURLOPT_POST, 1);   // Do a regular HTTP POST
 curl_setopt($ch, CURLOPT_POSTFIELDS, "var1=value1&var2=value2&var3=value3");   // The full data to post in a HTTP "POST" operation
 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);   // Return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. 
 $curl_response = curl_exec ($ch);   // Perform a cURL session
 curl_close ($ch);    // Close a cURL session
 $response = json_decode($curl_response);   // Returns the value encoded in json
 session_start();  
 foreach($response as $key => $val) $_SESSION[$key] = $val;  
 var_dump($_SESSION);  
 ?>  


Code for the page you call via cURL:
 <?php  
 session_start();  
 /* If you are working on a page that will connect to a database then:  
  * - put all require or include statements  
  * - db connection instantiation  
  * - script to process the $_POST variables  
  * - assign $_SESSION variables  
  */  
 echo json_encode($_SESSION);   // Returns the JSON representation of a value
 ?>  

Wednesday, May 22, 2013

How to revert git patch

git apply -R patchname.patch

Monday, May 13, 2013

Conflict With Rogue RPM

In this example, MySQL causes the installation process to fail:
[20130128.230346] Testing RPM transaction
[20130128.230348] error: Failed dependencies:
[20130128.230348] MySQL conflicts with *mysql-5.0.77-4.el5_4.2.i386*
[20130128.230348] W Exit Code: 254
[20130128.230348] ***** FATAL: Test install failed: error: Failed dependencies:
[20130128.230348] MySQL conflicts with mysql-5.0.77-4.el5_4.2.i386
[20130128.230348] The Administrator will be notified to review this output when this script completes
[20130128.230348] E Error testing if the RPMs will install: Died at /usr/local/cpanel/scripts/updatenow.static line 12517.
[20130128.230348] E Detected events which require user notification during updatenow. Will send iContact the log
Notice the version of MySQL in the update log. We can look closer at it with the following command: rpm -qa|grep mysql-5
# rpm -qa|grep mysql-5
mysql-5.0.77-4.el5_4.2
Then, we can compare that RPM to the other MySQL RPMs in the repository:
MySQL-server-5.5.28-2.cp.1132
MySQL-devel-5.5.28-2.cp.1132
MySQL-client-5.5.28-2.cp.1132
MySQL-test-5.5.28-2.cp.1132
MySQL-shared-5.5.28-2.cp.1132
The solution to this conflict is to remove the rogue RPM file and run the cPanel update process again.

Source: http://docs.cpanel.net/twiki/bin/view/AllDocumentation/InstallationGuide/RPMTroubleshoot

In order to resolve this cPanel support suggested running:


rpm -e --nodeps --justdb mysql-5.0.45-7.el5.i386
If done correctly, it will just drop you back to the prompt. Then try your update again.  
What the above command does is not actually erase any RPM or dependencies from your server. It just hides the installed RPM from the RPM database so that the cPanel updater doesn't see it and won't have a conflict with it when it goes to install the proper version of MySQL that it wants to install.


Source: http://blog.zweck.net/