|
Hello friends,
I am learning google API I want to retrieve google contacts using Authsub. And second thing is that i want to use secure token. I have X.509 certificate with private key.
In first step I got token but in second step (To get AuthSubSessionToken) I got error : Invalid AuthSub token. Here my code. please, anybody have idea ?
Help me....
$url = "https://www.google.com/accounts/AuthSubSessionToken";
$token = $token;
$param['sigalg'] = "rsa-sha1";
$nonce = "15948".time()."49418";
$param['data'] = "GET https://www.google.com/accounts/AuthSubSessionToken ".time()." ".$nonce;
$private_key = "MY_PRIVATE_KEY";
$kvpairs = array();
foreach ($param as $k => $v) {
array_push($kvpairs, ($k . '=' . $v));
}
$query_string = '';
$query_string = implode('&', $kvpairs);
$base_string = 'GET'.'&'.$url .'&'.$query_string;
$param['sig'] = base64_encode(hash_hmac('sha1', $base_string, $private_key, true));
uksort($param, 'strcmp');
$header = 'Authorization: AuthSub token="'.$token.'" ';
foreach ($param as $k => $v)
{
$header .= $k . '="' .$v. '" ';
}
$header = trim($header," ");
$headers[]= $header;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$responce = curl_exec($ch);
curl_close($ch);
|
|
|
|
|
Hi guys,
using MAMP v2.0 on Mac ____ Apache/2.0.64 (Unix) -- PHP/5.3.5 -- DAV/2 mod_ssl/2.0.64 -- OpenSSL/0.9.7l -- MySQL 5.5.9
I have a script I am trying to run and It appears to be giving me major memory leaks, which I have attempted to debug and cannot work out how to fix.
Basically, the script is part of a file manager module. It processes the download of a file when given an ID.
The entire file is stored in a database table, as a BLOB, in 64kb chunks (per record), and is streamed down to the client on request.
Database: file_management
Tables: file_details, file_data
file_details:
FileID - int(10) AUTO_INCREMENT
FileTypeID - int(10)
FileType - varchar(60)
FileName - varchar(255)
FileDescription - varchar(255)
FileSize - bigint(20)
FileUploadDate - datetime
FileUploadBy - int(5)
file_details:
FileDataID - int(10) AUTO_INCREMENT
FileID - int(10)
FileData - BLOB
The error I am actually getting is this one (from php error log):
[31-Oct-2011 09:47:39] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 63326173 bytes) in /root/htdocs/file_manager/file_manager_download.php on line 150
Now, the actual function of downloading works if the file is small enough, in this case, less than 40mb, however once it goes over that, like the 60mb file in the error above, it fails. All it does is download a 0kb file.
Obviously, 134217728 bytes is more than 63326173 bytes (128mb vs 60mb).
the Allowed memory size of 134217728 bytes is the directive in php.ini: "memory_limit = 128M ; Maximum amount of memory a script may consume"
If I set this to 256M, it allows me to download that 60mb file, as well as up to about an 80mb file.
Also, if I set this to 1024M it allows me to download a 260mb file and possibly bigger.
So you can see that the problem is a leak somewhere in the script that is eating up all the memory.
Here is the download script:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL & ~E_NOTICE);
$strDB=mysql_connect("localhost","username","password")or die ("Error connecting to mysql.. Error: (" . mysql_errno() . ") " . mysql_error());
$database=mysql_select_db("file_management",$strDB);
if (isset($_GET["id"])) {
$nodelist = array();
$sql_GetFileDetails = "
SELECT
FileID,
FileTypeID,
FileType,
FileName,
FileDescription,
FileSize,
FileUploadDate,
FileUploadBy
FROM file_details WHERE FileID = '".$_GET["id"]."';";
$result_GetFileDetails = mysql_query($sql_GetFileDetails) or die ("No results for this FileID.<br>Your Query: " . $sql_GetFileDetails . "<br> Error: (" . mysql_errno() . ") " . mysql_error());
if (mysql_num_rows($result_GetFileDetails) != 1) { die ("A MySQL error has occurred.<br>Your Query: " . $sql_GetFileDetails . "<br> Error: (" . mysql_errno() . ") " . mysql_error()); }
$FileDetailsArray = mysql_fetch_assoc($result_GetFileDetails);
$sql_GetFileDataNodeIDs = "SELECT FileDataID FROM file_data WHERE FileID = ".$_GET["id"]." order by FileDataID";
if (!$result_GetFileDataNodeIDs = mysql_query($sql_GetFileDataNodeIDs)) { die("Failure to retrive list of file inodes<br />Your Query: " . $sql_GetFileDataNodeIDs . "<br /> Error: (" . mysql_errno() . ") " . mysql_error()); }
while ($row_GetFileDataNodeIDs = mysql_fetch_assoc($result_GetFileDataNodeIDs)) {
$nodelist[] = $row_GetFileDataNodeIDs["FileDataID"];
}
$FileExtension = explode(".",$FileDetailsArray["FileName"]);
$FileExtension = strtolower($FileExtension[1]);
switch ($FileExtension) {
case "mp3": $ctype="audio/mp3"; break;
case "wav": $ctype="audio/wav"; break;
case "pdf": $ctype="application/pdf"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="application/force-download"; break;
case "png": $ctype="application/force-download"; break;
case "jpeg": $ctype="application/force-download"; break;
case "jpg": $ctype="application/force-download"; break;
default: $ctype="application/force-download";
}
header("Date: ".gmdate("D, j M Y H:i:s e", time()));
header("Cache-Control: max-age=2592000");
header("Accept-Ranges: bytes");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"".$FileDetailsArray["FileName"]."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Type: ".$FileDetailsArray["FileSize"]);
ob_end_clean();
ob_start();
ob_start("ob_gzhandler");
$sql_GetFileDataBlobs = "SELECT FileData FROM file_data WHERE FileID = ".$_GET["id"]." ORDER BY FileDataID ASC;";
if (!$result_GetFileDataBlobs = mysql_query($sql_GetFileDataBlobs)) { die("Failure to retrive list of file inodes<br />Your Query: " . $sql_GetFileDataBlobs . "<br /> Error: (" . mysql_errno() . ") " . mysql_error()); }
while ($row_GetFileDataBlobs = mysql_fetch_array($result_GetFileDataBlobs)) {
echo $row_GetFileDataBlobs["FileData"];
}
ob_end_flush();
header('Content-Length: '.ob_get_length());
ob_end_flush();
}
?>
I have used Xdebug and output the results for peak memory usage, but nothing appears to be going anywhere near the limits, in total the peak memory usage was something like 900kb for the page.
So I am thinking it is aggregating the file chunks into memory and not letting them go, or something similar, but the file chunks are the only thing that would reach that amount of memory, causing the script to fail.
I can provide the script to upload a file to the database so you can test my script if you like, just let me know
Cheers for any help!
Mick
modified 30-Oct-11 21:03pm.
|
|
|
|
|
I have partially solved this problem.
I was told on another forum to add ob_flush(); to the While loop where I am echoing out my file nodes. This appears to work in part; it allows me to download a 140mb file with only 128M memory_limit directive set in php.ini
However, when I attempt to download a 250mb file the error is thrown again:
[31-Oct-2011 11:46:01] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 132392961 bytes) in /root/htdocs/file_manager/file_manager_download.php on line 125
[31-Oct-2011 11:46:01] PHP Stack trace:
[31-Oct-2011 11:46:01] PHP 1. {main}() /root/htdocs/file_manager/file_manager_download.php:0
[31-Oct-2011 11:46:01] PHP 2. ob_flush() /root/htdocs/file_manager/file_manager_download.php:125
As you can see, it is getting within 2mb of the limit and then failing, and I can actually see it streaming the file to the browser, it gets to about 200mb of the 250mb file, and fails.
The while loop looks like:
while ($row_GetFileDataBlobs = mysql_fetch_array($result_GetFileDataBlobs)) {
echo $row_GetFileDataBlobs["FileData"];
ob_flush();
}
so it appears to be working better than before, but that REALLY large files dont work.
The question is then, do I need to increase my memory_limit directive, or should it be streaming effectively with the limit of 128M but I still have a problem with my code and the way it is, or is not, trashing the memory it doesn't need.
Cheers
Mick
|
|
|
|
|
Ok, I have added to it and resolved the problem.
The problem was two fold.
1 - I wasn't using ob_flush() inside the while loop. I added that in and it appeared to free up a lot of memory, enabling larger downloads, but not unlimited.
For example, with memory_limit = 128M i could now download more than 40mb, in fact i could now get up to around 200mb. But this is where it failed again. First memory issue problem solved though.
LESSON 1: Flush your objects!
2 - I was using mysql_query to retrieve the results for my SQL Query. The problem is that it buffers these results, and this was adding to my memory limit issue.
I ended up using mysql_unbuffered_query instead and this now works flawlessly.
This does however come with some limitations, that it locks your table while reading results.
LESSON 2: Don't buffer mysql results if not required! (within programmatic limitations)
FINAL LESSON:
All of these fixes work, however, it requires some more testing to ensure that there is no problems with the combination of them.
Also, I have learned a lot more about objects and php memory allocation, I just wish there was a way to visually debug the process a little better than what xdebug offers. If anyone has any ideas on how xdebug could have actually shed some light on this process, please let me know in the comments.
Hope this helps someone else out in the future.
|
|
|
|
|
Also use unset function to removed unused variables and array..
|
|
|
|
|
I am using this code to send emails but when the user send something in arabic I get unreadable message like this:
تجربة من Ø§Ù„ØµÙØØ© العربية
here is my code.. please help..
<?php
$ToEmail = 'reception@rmc.bh';
$EmailSubject = 'Email from rmc.bh ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= 'Bcc: dhr@rmc.bh' . "\r\n";
$mailheader .= 'Bcc: jkh@rmc.bh' . "\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY .= nl2br($_POST["message"])."<br><br><br><hr>";
$MESSAGE_BODY .= "IP Address: ".$_SERVER["REMOTE_ADDR"]."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
header('Location: http://www.rmc.bh/thankyou.php');
?>
|
|
|
|
|
In the email header you are setting the MIME content type as HTML, using the ISO-8859-1 character set - that's the Latin-1 set, so that might explain why the Arabic is coming out wrong.
The simplest solution could be to change the header to use "charset=utf-8" instead of iso-8859-1, and also check that your application uses UTF-8 throughout (in HTTP headers, on the web page, form fields, database fields, etc.)
|
|
|
|
|
Hi,
I have skills saved in a table called skills in mysql with field name called skill_name.
I want to retrieve the skills and display like a cloud so one will have small font and next one will have larger font, etc..
something like this image:
http://www.rmc.bh/temp.jpg[^]
can anyone guide please..
|
|
|
|
|
|
Hi,
I wantt o know how can I have a facebook-like or linkedin-like modal dialog they used for properties and alerts?
Thanks,
Jassim
|
|
|
|
|
Modal box in html is clever combination of images. If you can figure out how to create that modal box, then rest is easy.
you can call the page with the modal box, It will have to have some javascript code to show the modal box properly., rest is up to you..
|
|
|
|
|
I am developing Google app (with oauth 1.0)that retrieve google contatcs but i got error : signature_invalid please help me Thx in advance
function GetRequestToken()
{
$consumer = 'YOUR_CONSUMER_KEY';
$secret = 'YOUR_CONSUMER_SECRETE';
$callback = 'http://localhost/Gcontacts/welcome/redirection';
$sign_method = 'HMAC-SHA1';
$version = '1.0';
$scope = 'https://www.google.com/m8/feeds/';
$path = "/accounts/OAuthGetRequestToken";
$mt = microtime();
$rand = mt_rand();
$nonce = md5($mt.$rand);
$time = time();
$url = 'https://www.google.com/accounts/OAuthGetRequestToken';
$post = array(
'oauth_callback' => $callback,
'oauth_consumer_key' => $consumer,
'oauth_nonce' => $nonce,
'oauth_signature_method' => $sign_method,
'oauth_timestamp' => $time,
'oauth_version' => $version,
'scope' => $scope
);
$post_string1 = '';
foreach($post as $key => $value)
{
$post_string1 .= $key.'='.($value).'&';
}
$post_string1 = trim($post_string1, '&');
$key_part = $this->urlencodeRFC3986($secret);
$key = $key_part;
$base_string = $this->calculateBaseString($scope, "GET", $post);
echo $base_string;
$signature = base64_encode(hash_hmac('sha1', $base_string, $key,true));
$post_string1 .= 'oauth_signature'.'='.urlencode($signature);
$post['oauth_signature'] = $signature;
$header[] = 'POST'.$path.'?scope='.$scope.' HTTP/1.1';
$header[] = 'Content-Type: application/x-www-form-urlencoded';
$header[] = 'Accept: */*';
$header[] = $this->calculateHeader($post).', Content-Type: application/x-www-form-urlencoded ,Host: www.google.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'scope='.$scope);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
curl_close($ch);
}
private static function urlencode_rfc3986($value)
{
if(is_array($value)) return array_map(array('Welcome_model', 'urlencode_rfc3986'), $value);
else
{
$search = array('+', ' ', '%7E', '%');
$replace = array('%20', '%20', '~', '%25');
return str_replace($search, $replace, urlencode($value));
}
}
function calculateBaseString($url, $method, array $parameters)
{
$url = (string) $url;
$pairs = array();
$chunks = array();
uksort($parameters, 'strcmp');
foreach($parameters as $key => $value)
{
if(is_array($value)) $parameters[$key] = natsort($value);
}
foreach($parameters as $key => $value)
{
if(substr_count($url, $key . '=' . $value) == 0) $chunks[] = self::urlencode_rfc3986($key) . '%3D' . self::urlencode_rfc3986($value);
}
$base = $method . '&';
$base .= urlencode($url);
$base .= (substr_count($url, '?')) ? '%26' : '&';
$base .= implode('%26', $chunks);
$base = str_replace('%3F', '&', $base);
return $base;
}
function calculateHeader(array $parameters)
{
$chunks = array();
foreach($parameters as $key => $value) $chunks[] = str_replace('%25', '%', self::urlencode_rfc3986($key) . '="' . self::urlencode_rfc3986($value) . '"');
$return = 'Authorization: OAuth ';
$return .= implode(',', $chunks);
return $return;
}
function urlencodeRFC3986($string)
{
return urlencode($string);
}
|
|
|
|
|
You need to be very careful while doing this sort of thing - any little errors are going to break it, and can be hard to track down. A few I've spotted are:
- You have the 'scope' parameter out of sequence when building the data to sign. Data must be ordered alphabetically by key for the oauth signature to be correct.
- You use "GET" as a parameter for calculateBaseString although you're using POST
- You miss out the & delimiter when adding the oauth_signature
- You call curl_setopt($ch, CURLOPT_POSTFIELDS twice, overwriting the OAuth signed data with a single parameter.
It's very possible there are other errors I've not spotted.
Niall
|
|
|
|
|
The problem that we want you to help us in solving it is as follows :
We have an excel sheet containing some data.
We want to import this data to a mySql database to be used by a certain application.
By importing this data through transferring it to CSV format, the data was successfully imported but the Arabic data was not displayed in the application while this data is displayed during browsing the database inside the MySql.
If the data is entered through the application and then retrieved , the Arabic data is displayed correctly.
We need to import this data (excel sheet) inside the MySql such that it is displayed correctly inside the application.
Hint :I'm use UTF-8
|
|
|
|
|
I think a CSV is ascii only. UTF-8 would be lost.
Chris J
www.redash.org
|
|
|
|
|
I traditionally live in the client app world, so minimizing lines of code is more important than performance, so my coding style is heavy on common functions, etc.
Now that I am working on a web app (PHP and mySQL), I find myself second guessing everything. Here is an example. I am working on a shopping cart for an existing site. There are multiple places where the price of a particular product is returned:
Product Page
Cart over view
Buy process page,
receipt print,
etc.
In most cases, the product data (price) is already available, but the price can vary in different circumstances. I'm considering one function that gets passed the important variables, calculated the price of the product, and returns that price. However, to do so will require polling the database each time each price is requested (in some cases that is multiple prices on one page, so multiple calls to the database while the page is loading).
So my question is really one of best practice. How much of a noticeable performance hit does each call to the database take? Is it common to try to reduce the number of mysql calls? Do you not care? should each page have its own code, and just copy paste all over, and tweek each place where common data is shown?
There is a lot of how to questions (I have posted them) but I am hoping the community here can offer some more higher level theory.
Thank you in advance!
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
I cannot answer your question directly,
Some issues first of all if you a can create common function that will be used by multiple page, then make that one function.
From my experience: making software using php sometime helps a lot. specially development time. But I have faced some issue when I cannot depend on php.
I have faced a problem with one of my Software. I had to calculate stock by daily basis, Its not simple calculation which can be based on simple (insert into stock)-sales+(return from customer), Its more complicated than that. Because we have a different kind of stock management just because of type of product. The result is php page suffers big time. it cannot show the result. most case it ran out of memory. So, I solved it by C. I developed this page using C
Another example is, report making. I take support from pdf making class MPDF(they are vanished, i cant find there site anymore). But It cannot handle big data, memory suffers. So, Now I am building them in C. Finally my point is PHP gives a great way of programming but not very good idea in every case...
|
|
|
|
|
Thanks. You say: if you a can create common function that will be used by multiple page, then make that one function.
My main question is if doing so causes multiple MySQL calls that would not otherwise be required, is that bad practice?
Thanks in advance.
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
some of the problem can be solved by single query, some of them are not possible in single queries
if possible use multiple query
|
|
|
|
|
Follow the link below:
http://codeigniter.com/forums/viewthread/202515/
|
|
|
|
|
I find that the iostat in Linux gives the average disk queue length different from Window.
Window use Little's Law, but Linux use "weighted # of milliseconds spent doing I/Os" (Last Field in /proc/diskstats) divided by the duration. I have searched in Google but I cannot find any mathematical explanation on this.
Could anyone give me some pointers? 
|
|
|
|
|
|
I hate you
Re-phrased: could someone give me some reference?
|
|
|
|
|
int x = 0;
int& rX = x;
Sorry. I too could not resist prescribing humor.
Somebody in an online forum wrote: INTJs never really joke. They make a point. The joke is just a gift wrapper.
|
|
|
|
|
Hi,
I want to ask what's similar to visual studio in the PHP world to use for IDE development?
Thanks,
Jassim
|
|
|
|
|